开发者

C++ "class Foo return Bar" and "class Bar return Foo" possible?

Is it possible to define C++ classes Foo and Bar s.t.

clas开发者_如何学JAVAs Foo {
  Bar makeBar();
};

class Bar {
  Foo makeFoo();
};

?

Thanks!


Yes it is, you just have to put forward declarations at the top.

class Foo;
class Bar;

class Foo {
  Bar makeBar();
};

class Bar {
  Foo makeFoo();
};


Yes. You can do it with a forward declaration.

For example, in Foo.h, add:

class Bar;

class Foo {
    Bar makeBar();
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜