sadun wrote:
i have two classes...
public class1{
// properties
class2 copy;
}
public class2{
// properties
create copy of class1;
}
i got error in class1 that "class2 is undefined"... however intelli
show shoutcut of class2. if compiler goes step by step; while
declaring class1 it is possible to be class2 undefined but it is too
moronish...
how could i solve it ???
ps: if i take class1 bottom of class2 then it says that class1 is
undefined :)
It's not a compiler bug, but a design bug. You simply can't have classes
that are co-dependent in this way. Since C++ classes are "value types",
when you create a member of "class2" inside "class1", you're actually
embedding a complete instance of class1 (unlike Java or C# when you're
effectively embedding a pointer or reference to an instance of class1).
Naturally if class2 contains a class1, then class1 cannot contain a class2,
since that would result in a data structure of infinite size (since 1
contains 2 contains 1 contains 2 ...).
Now, for what you really wanted:
class class2;
class class1
{
class2* m_c2;
};
class class2
{
class1* m_c1;
};
Sounds like you need to do some reading in an introductory C++ book.
-cd