Original Post
🔒 Locked
C++ class problem
Advertisement
class F1
{
class F2 member;
};
class F2
{
F1 member;
};
This seems risky at best, though. You see, FirstClass has a SecondClass which has a FirstClass which has a SecondClass which has a FirstClass which has a SecondClass which has a FirstClass which has a SecondClass, etc. Is this just an over simplification or is this what you are actually doing?
Quote:
Original post by woytah
Hm... forward declarations seems not working. This is only a simplification of my problem. Somehow I've managed to move class declaration, and remove some members so now it works. But should I do if moving/removing will not be possible?
Use references and pointers, which only require a forward declaration. References for pass-by-reference, const references for pass-by-value and pointers for internal storage are usually enough. Remember that if your design involves two classes containing each other (as opposed to simply referencing one another), you have a problem.
Ezbez has it right: a forward declaration cannot make this specific piece of code work. It only allows you to use the type in pointers, references and function prototypes, where no information about the type's actual size is needed.
class SecondClass;class FirstClass{ SecondClass<font color=red>*</font> Member;};class SecondClass{ FirstClass Member;};
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement