its late and i don't feel like thinking about how i need to go about doing this so anyone who has run into this problem before could you please help?
i have two classes that refer back to each other and it can't compile in the normal fashion
thanx
Printable View
its late and i don't feel like thinking about how i need to go about doing this so anyone who has run into this problem before could you please help?
i have two classes that refer back to each other and it can't compile in the normal fashion
thanx
What is the error?
Are you using pointers to the other class, because you might be able to use forward declarations...
class b;
class a {
b* pb; };
class b {
a* pa; };
yes, thank you, that works
the only problem is im using a member function from one of the classes and its telling me the function doesn't exist?
would i need to do something like this?
class b
{
void nothing();
};
class a
{
void func()
{b->nothing();}
b* pb;
};
class b
{
void nothing()
{ cout << "nothing";}
a* pa;
};
That was just for DNA's info...Quote:
Originally posted by CornedBee
class b; <- This is a forward declaration.
class a {
b* pb; };
class b {
a* pa; };
Umm the only thing I can suggest is... Do not "inline" the function that way. Move its definition into a source file. If you still want it inline you can specify that by placing the keyword "inline" before the function header.
ok, well the function is in a seperate file, i just did that for my little example
ok i think i got it now
i need to include all the .cpp code after ALL of the headers have been defined
i was wrong, it still doesn't work
i wish there were more people on this forum
always include all headers first.
inline functions are static by definition, so
The functions only exist in the module they were defined in. Solution: put the functions in a special file (usual extension is .inl), then include this file at the end of the header.Code:// a .h file, included by both .cpp files
class a{
public:
void foo();
};
// one .cpp file:
inline void a::foo()
{
// code
}
// another .cpp file:
void main()
{
a obj;
obj.foo(); // linker error!
}
You could also place the code in a.inl directly in a.h, but the separation makes it more readable.Code:// a.h
class a{
public:
void foo();
};
#include "a.inl"
// a.inl
inline void foo()
{
// foo
}
// some.cpp
void main()
{
a obj;
obj.foo(); // OK
}
// someother.cpp
void func()
{
a obj;
obj.foo(); // OK
}
How about:
class a
{
b thisb; // not a pointer!
}
class b
{
a* pa;
}
???
Possible, but you must reorder:
Code:class a;
class b {
a *pa;
};
class a {
b ob;
};
Not sure why, but that doesn't seem to compile. . .
//{{AFX_INCLUDES()
#include "MyStatic.h"
//}}AFX_INCLUDES
class CInterfaceView : public CFormView
{
...
//{{AFX_DATA(CInterfaceView)
...
CMyStatic m_Att1Val;
...
//}}AFX_DATA
...
}
#include "interfaceView.h"
class CInterfaceView;
class CMyStatic: public CStatic
{
...
CInterfaceView* parentform;
...
}
That leads to over a thousand errors. :(
Remove the #include "interfaceView.h" from MyStatic.h.
There's also no reason to store the pointer you're storing. Just use GetParent (or GetParentWindow) and cast the result.
Sweet! Thanks again.