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?

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.

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.

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.

Assumed solution--

#define Class class

class Link;
class Room;

Class Space
{
	//...
};

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

Class Link : public Space
{
    Room* r;
    //...
};
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.