--- snip ---
namespace mySpace {
class ClassA; // <--- error is on this line
class ClassB
{
private:
…
--- snip ---
Anyone see what might be wrong with this?
class A; // This Compiles Fine
class B { // gcc version 3.3.5
private:
A *a;
public:
B(){};
~B(){};
};//B
}//mySpace
+++++++++++++++++++++++++++++++++++++++++++++
namespace mySpace {
class A;
class B {
private:
A *a;
public:
B(){a = new A();}; //This gives the Following errors:
~B(){}; //
};//B
}//mySpace
Test.cpp: In constructor `mySpace::B::B()':
Test.cpp:14: error: invalid use of undefined type `struct mySpace::A'
Test.cpp:4: error: forward declaration of `struct mySpace::A'
You can have a Pointer to an A class but as soon as you try to use it
inside the B class the compiler chokes. Either #include A.hh or
define
A inside of namespace mySpace in another file, or, if A is only used
by B, as an inner class inside of the B class definition.
Oh-By-The-Way: this is the Objective-C group. Objective-C
neatly gets around this nut by being dynamically typed.
@class SomeClass // forward decl
@interface B: NSObject
{
SomeClass *a;
}
@end
@implementation B
{
- initWithA(SomeClass *A)
{
a = A;
}
@end
In this case I believe the compiler will warn about SomeClass but
compile OK.