【问题标题】:class and variable declaration( of same class type)类和变量声明(相同的类类型)
【发布时间】:2014-01-05 07:13:07
【问题描述】:

这个声明在 c++ 中正确吗?

class Abc
{
struct xyz x;

};

struct xyz
{
Abc abc;
int instances;
};

我收到以下错误。 错误:字段“x”的类型不完整

那么,如果我有上述用例,我该如何创建呢?

【问题讨论】:

    标签: c++ class struct declaration


    【解决方案1】:

    您无法做到这一点,因为这两种类型之间存在循环依赖关系。您可以通过使用指向结构的指针作为成员和 forward declarations 来实现这一点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-17
      • 1970-01-01
      • 2015-03-09
      • 1970-01-01
      • 1970-01-01
      • 2017-11-15
      • 2018-04-18
      • 1970-01-01
      相关资源
      最近更新 更多