![]() |
|
"does not name a type" error, general c++ question |
evilmax17
Member #7,606
August 2006
|
Hello all, I have this code: class B{ I get the error "A does not name a type" when declaring A hello. Basically, I want to instatiate a member of class A in class B. What syntax am I missing? Thanks in advance |
James Stanley
Member #7,275
May 2006
![]() |
You need to define A before B. Also, use code tags, it makes it easier to read. |
Milan Mimica
Member #3,877
September 2003
![]() |
Put definition of class A before class B. edit: arhg, matter of seconds
-- |
evilmax17
Member #7,606
August 2006
|
Thanks for the response, but what if I have the following? class B{ public: A hello; B(){} ~B(){} }; class A{ public: B hello; A(){} ~A(){} };
|
Milan Mimica
Member #3,877
September 2003
![]() |
You cannot have that. Think about how much memory would that require - infinite. B includes A, which includes B, which includes A... But you can have pointers:
-- |
|