且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我可以让c ++代码结构看到对方吗?

更新时间:2023-12-05 14:30:46

不,你不能这样做。这将是一个无尽的递归。

No you can't do this. It would be an endless recursion.

您可以使用引用或指针。请参见此处如何操作:

You could use a reference or a pointer though. See here how to do this:

struct structure2; // <<< forward declaration 
struct structure1
{
   structure2* st; // <<< use a pointer (or reference) 
   structure1(structure2* s2) : st(s2) {} // <<< initialize the pointer
};

struct structure2
{
   structure1 st;
   structure2() : st(this) {} // <<< pass the pointer
};

现场演示