capnjazz
asked on
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;
.
};
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;
.
};
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
That is certainly A problem and probably THE problem. Alex, you should answer.
ASKER
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);
}
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);
}
"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", ....};
char types [20][]
or better yet (usually better, it depends) define a 1 dimensonal array of character pointers, like
char *types[] = {'Arrival", ....};
ASKER
stress will do it to you. thanks
Is anything left.
>> 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.
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.
ASKER
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" };
i'm getting: an array may not have elements of this type.
char types[5][] = { "Arrival", "SignIn", "Renewal", "Register", "Cashier" };
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.
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.