I need a way to do the following and I cannot think of one, this is what I have so far:

typedef Obj2*(*Reaction)();
class Obj1
{
    public:
    Reaction reaction;
};
class Obj2
{
    public:
    unsigned int numobj1;
    Obj1 *objects;
};
class Obj3:Obj2
{};

Can you find any way of doing this within the syntactical rules of C++?

Recommended Answers

All 2 Replies

Presumably you mean using Obj2 in the typedef despite it not being declared yet. You can forward declare the class to remove syntax errors:

class Obj2;
typedef Obj2*(*Reaction)();

Thanks, that works!

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.