Main Page | Report this Page
Computers Forum Index  »  Computer Languages (Objective-C)  »  forward declaration of 'struct::Class'...
Page 1 of 1    

forward declaration of 'struct::Class'...

Author Message
Joe...
Posted: Wed Oct 28, 2009 5:17 am
Guest
I'm importing an XCode 2.0 project into XCode 3 and things are breaking
all over the place. This code used to compile for me. The error is …

Forward declaration of 'struct mySpace::ClassA'

--- snip ---
namespace mySpace {

class ClassA; // <--- error is on this line

class ClassB
{
private:

--- snip ---

Anyone see what might be wrong with this?
 
spikeysnack...
Posted: Wed Oct 28, 2009 12:10 pm
Guest
namespace mySpace {

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.

at (no spam) class SomeClass // forward decl

at (no spam) interface B: NSObject
{
SomeClass *a;
}
at (no spam) end
at (no spam) implementation B
{
- initWithA(SomeClass *A)
{
a = A;
}
at (no spam) end
In this case I believe the compiler will warn about SomeClass but
compile OK.
 
 
Page 1 of 1    
All times are GMT
The time now is Tue Dec 08, 2009 3:21 am