Domanda

Let I've two interfaces:

class foo{
public:
    virtual void fooo(bar * b)=0;
}

class bar{
public:
    virtual void barr(foo * f)=0;
}

But this code snippet is ill-formed. How can I write this interfaces correctly?

È stato utile?

Soluzione

How can I write this interfaces correctly?

You can always forward declare classes and use pointers or references in the code that sees the forward declaration.
As soon any code needs to refer class members, the full class declaration must be seen.

class bar; // << Note the forward declaration
class foo{
public:
    virtual void fooo(bar * b)=0;
}

class bar{
public:
    virtual void barr(foo * f)=0;
}

Altri suggerimenti

Just forward declare bar;

class bar;

class foo{
public:
    virtual void fooo(bar * b)=0;
}

class bar{
public:
    virtual void barr(foo * f)=0;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top