0

I'm trying to do a program involving a base class and subclasses, whose subclasses use each other. In terms of code:

Class Space
{
   ...
};
Class Room : public Space
{
    Link* l;
    ...
};
Class Link : public Space
{
    Room* r;
    ...
};

Now I'm getting "ISO C++ forbids declaration of `Link' with no type" errors, understandably. But I can't figure out how to rearrange or change it so it isn't trying to use a type who's definition it hasn't seen yet. Suggestions?

3
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by Alex Edwards
0

you could try looking up forward declarations in your favorite reference material, though without knowing more details about the program my first thought is whether you should redo the heirachy/class relationships to avoid the entanglement completely if possible.

0

Redesigning the class isn't an option unfortunately. Need a way of declaring the class type before its used/implemented, though I'm not sure exactly how.

0

Then try my other suggestion and look up forward declarations to see if you can get it to work. Good luck. Time for me to get some shuteye.

0

Assumed solution--

#define Class class

class Link;
class Room;

Class Space
{
	//...
};

Class Room : public Space
{
    Link* l;
    //...
};

Class Link : public Space
{
    Room* r;
    //...
};
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.