2-Way Communication between classes

Using:  MS Visual Studio 6.0 & Unix

Situation:  I'm creating a simulation of the MVA.  I have 2 classes that need to communicate to each other, and Event and Mva class.

Problem:  Having a clean compile between the two.  In other words my Event class when i compile it says:
         ---- Event.cpp ----
   'Event' : function should return a value; 'void' return type assumed
   syntax error : missing ';' before 'public'
   'operator <' must have at least one formal parameter of class type

          ----- Mva.cpp ------
   syntax error : identifier 'Event'
   'Queue' : 'Event' is invalid as template argument '#1', type expected

so it seems it's not recognizing my Event class as a "class".????

---------------------------------------------------------------------------------------------------------

****** Event.h********
#ifndef EVENT_H
#define EVENT_H

class Mva;
class Event()
{
      public:
                                Event();
                                void execute(Mva &);
                .
                .
                private:
                .
                .
};

***** Event.cpp ******
#include "Mva.h"


***** Mva.h *********
#ifndef MVA_H
#define MVA_H

#include "Event.h"
class Mva
{
      public:
            Mva();
                                bool getNextEvent(Event &);
                                .
                                .
                private:
                                Queue<Event>  eventList;
                                .
};
capnjazzAsked:
Who is Participating?
 
alex_rConnect With a Mentor Commented:
Are you sure that this is

class Event() { ....

and not:

class Event {

0
 
nietodCommented:
That is certainly A problem and probably THE problem.  Alex, you should answer.
0
 
capnjazzAuthor Commented:
i might as well just smack myself

also...this one's driving me crazy.
error:  too many initializers
char types[] = { "Arrival", "SignIn", "Renewal", "Register", "Cashier" };

thanks, i really just needed someone else to take a look @ it for me.


void Mva::addEvent(const Event &e)
{
      char types[] = { "Arrival", "SignIn", "Renewal", "Register", "Cashier" };
      cout << "Event Added: " << types[e.getState()] << endl;

      eventList.enqueue(e);
}
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
nietodCommented:
"char types[]" defines A array (a one-dimensional array) of characters.  You need to define a 2 dimensional array of characters, like

char types [20][]

or better yet (usually better, it depends) define a 1 dimensonal array of character pointers, like

char *types[] = {'Arrival", ....};
0
 
capnjazzAuthor Commented:
stress will do it to you.  thanks
0
 
basantCommented:
Is anything left.
0
 
nietodCommented:
>> Is anything left
If not, capnjass, you should close the question.  If alex_r helped you, you should accept his comment as an answer.  Otherwise, if no expert helped you enough, you can delete the question.
0
 
capnjazzAuthor Commented:
there's always more... hopefully this is it.

i'm getting: an array may not have elements of this type.
char types[5][] = { "Arrival", "SignIn", "Renewal", "Register", "Cashier" };
0
 
nietodCommented:
That is because the array you declared is an array of another array whose type is char[5].  This array is not long enough to store the names you specified.   You could do

char types[20][] = { "Arrival", "SignIn", "Renewal", "Register", "Cashier"};

but that makes ever entry 20 chars long, enough to store a 19 character long string.  That means it wastes space when some words are shorter.

If the array will not be changed during the course of the program, as is often the case with this sort of data, you should instead use

const char *types[] = { "Arrival", "SignIn", Renewal", "Register", "Cashier"};

This is usually more space efficient because it stores pointers to the character arrays and these character arrays are just the length that is needed.
0
All Courses

From novice to tech pro — start learning today.