>I have the definitions of classes A and B in a header file. Class A has a
private member of type B. Class B is defined after class A in the header
file. I place a forward declaration of class B above class A but VS.NET
still complains with:
For the compiler to know the exact size of a class, it must know the
exact size of its members. By putting only a declaration, the
compiler does not know the size of the class, hence the error.
error C2079: 'TextDB::TextDB::database_version' uses undefined class
'TextDB::TextDB_Version'
namespace TextDB
{
class TextDB_Version;
class TextDB
{
private:
TextDB_Version database_version;
};
class TextDB_Version
{
[...]
};
} // namespace TextDB
Is this because this is in a header file? I'm confused.
Take a look :
class A
{
int i;
};
Here the compiler knows 'A' will have the size
sizeof(int) + implementation_defined_things
In your class :
class TextDB
{
private:
TextDB_Version database_version;
};
the compiler tries the same thing :
sizeof(TextDB_Version) + implementation_defined_things
and just cannot find the size of TextDB_Version since you only
declared it.
You have got two choices :
1) Define the class TextDB_Version *before* TextDB
2) Make database_version a pointer and allocate the
memory dynamically
Jonathan