The problem we have been set is to make 3 classes which derive from a base class and 2 of these derived classes has a relationship with each other, now i can get only one of the derived classes to have a relationship with the other, but when i try to add a relationship to the other i cant scope problems i think. Any ideas pointers would be greatly appreciated.
Do you mean to say that 2 of the derived classes share a member which the 3rd one does not?
If so, you probably need an intermediary derived class, which contains those shared member(s) (either public or protected) - and derive the 2 "related" classes from this intermediary class. eg,
"Has-A" is typically implemented with data members. To get a circular relationship you can't use straight objects because a class has to be defined before it's instantiated and it can't be instantiated if any of the members have an incomplete type. However, you *can* have a pointer to an incomplete type and use a forward class declaration to create the circular dependency:
u cant use a claas without declareing it, if u will try to use it will generate a compile time error "missing storage-class type spacifiers"
however u can use a pointer of undeclareed class by giving a forward reference of undeclared class.
this problem arise because when we try to declare an object we tend to allocate memory for it, since class is not declared we dont know what amount of memory should be allocated, however when we declare a pointer we actually do not allocate memort for object therefore it works.
u cant use a claas without declareing it, if u will try to use it will generate a compile time error "missing storage-class type spacifiers"
however u can use a pointer of undeclareed class by giving a forward reference of undeclared class.
this problem arise because when we try to declare an object we tend to allocate memory for it, since class is not declared we dont know what amount of memory should be allocated, however when we declare a pointer we actually do not allocate memort for object therefore it works.
I'm impressed. It only took you a whole day to repeat my post using different words. :rolleyes:
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.