i have been attempting to pass an object into a function that belongs to a class both classes are in there own files…but when i try to pass the object as an argument for the function prototype it gives me an error saying that the object doesn’t exist… ill provide some pseudo code to demonstrate my problem
//class 1 .h
class Class1
{
public:
void function(Class2);//this is were one of my errors
};
//class 1 .cpp
void Class1::function(Class2 object )//another error
{
//stuff happens
}
//main.cpp
//then i simply call these functions like this
Class1 object;
Class2 object2;
int main()
{
object.function1(object2);
return 0;
}
and i get errors “Class2′ has not been declared”
and errors about Class1 prototype does not match any classes….
if someone could explain what im doing wrong it would be a great help also if more code is needed just ask and i will post it.
EDIT
when i was attempting to include class2`s header in class one i was using the wrong director as i forgot i had separated .h files into there own folder anyway now i have fixed that it all work thanks a lot everybody.
You’ll need to include Class2’s header file in Class1.h. That is:
If you are only using a pointer to Class2 as an argument, then you can forward declare Class2 instead of including the header, that is:
There’s some more info here if you’re interested.