Collection of Interfaces depends on each other

天涯浪子 提交于 2019-12-11 10:04:40

问题


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?


回答1:


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;
}



回答2:


Just forward declare bar;

class bar;

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

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


来源:https://stackoverflow.com/questions/23442038/collection-of-interfaces-depends-on-each-other

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!