Hello all,
I have this code:
class B{
public:
A hello;
B(){}
~B(){}
};
class A{
public:
A(){}
~A(){}
};
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
You need to define A before B. Also, use code tags, it makes it easier to read.
Put definition of class A before class B.
edit: arhg, matter of seconds
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(){} };
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:
1 | |
2 | class A; |
3 | |
4 | class B{ |
5 | public: |
6 | A *hello; |
7 | B(){} |
8 | ~B(){} |
9 | }; |
10 | |
11 | class A{ |
12 | public: |
13 | B *hello; |
14 | A(){} |
15 | ~A(){} |
16 | }; |