|
-
June 13th, 2012, 05:24 PM
#1
how to forward declare a class in a class ?
If you have a class having a pointer to a not-yet defined class, you can forward declare that class. But how do you do this if the class is a class defined inside another class.
Below is a sample of the problem, this is what I'd like to get compiling but now it doesn't. the
Code:
// Helper class. Basically a wrapped typed pointer.
template <typename Ty>
class ConstPtr
{
public:
const Ty* p;
const Ty& operator()() { return *p; }
};
class A
{
public:
class Item
{
public:
const char* szName;
ConstPtr<B::Item> b; // <-- Problem
};
typedef std::tr1::array<Item,3> Array;
static const Array All;
};
class B
{
public:
class Item
{
public:
const char* szName;
ConstPtr<A::Item> a;
};
typedef std::tr1::array<Item,2> Array;
static const Array All;
};
const A::Array A::All =
{
{
{ "one", &B::All._Elems[0], },
{ "two", &B::All._Elems[1], },
{ "three", &B::All._Elems[1], },
}
};
const B::Array B::All =
{
{
{ "red", &A::All._Elems[0], },
{ "blue", &A::All._Elems[1], },
}
};
Now the above is a simplified section of the problem, in reality I have several dozen of classes similar to A and B, with varying members in the Item classes.
I can't seem to figure out how to tell the compiler that at the definition of the A class that B::Item is a valid class and taking a pointer of it is ok.
if I change the ConstPtr<B::Item> to const void* the code compiles and "works" but I don't have a pointer of the right type in that case.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|