How do I get 2 classes to work that both depend on each other?( they are also in different files )
Is there anyway to have them both include each others .h file?
I get hundreds of errors having them include each other.
I am making a MenuWindow class that holds all the different menus and puts it into a class.
2 files that both depend on each other
2 files that both depend on each other
Computer too slow? Consider running a VM on your toaster.
Re: 2 files that both depend on each other
Yes, you can define both classes and just have them interact, but the best idea is to have a class with both inside, it just makes things simpler.
You need to make sure however, that when you use a class which is defined before another, that you pre-define it (or whatever it's called)
IE:
You need to make sure however, that when you use a class which is defined before another, that you pre-define it (or whatever it's called)
IE:
Code: Select all
//this is temp2.h
#include "Temp.h"
class A;
class B{
public:
B();
~B();
private:
A a;
};
Code: Select all
//this is temp.h
#include "Temp2.h"
class A{
public:
A();
~A();
private:
B b;
};
Re: 2 files that both depend on each other
why not put them in the same file?
and well for 2 classes to refer to each other the later defined class has to be declared before the 1st defined class, ex:
edit: lol, seems i was late
and well for 2 classes to refer to each other the later defined class has to be declared before the 1st defined class, ex:
Code: Select all
class Obj2;
class Obj1 {
Obj2 obj2;
};
class Obj2 {
Obj1 obj1;
};
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
Re: 2 files that both depend on each other
Thanks both of you.
Computer too slow? Consider running a VM on your toaster.