开发者

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

开发者 https://www.devze.com 2022-12-21 00:02 出处:网络
Is it possible to define C++ classes Foo and Bar s.t. clas开发者_如何学JAVAs Foo { Bar makeBar();

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

精彩评论

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