gpt4 book ai didi

c++ - 通过 TI 编译器使用定义类型的成员

转载 作者:行者123 更新时间:2023-11-28 06:44:09 26 4
gpt4 key购买 nike

我有一个看起来像这样的类:

class In {
public:
struct Member{
In name;
};

In() {}

private:
static const int aCapacity = 16;
static const int oCapacity = 16;
};

当我尝试编译它时出现错误:error #71: incomplete type is not allowed

此代码使用 Microsoft 编译器进行编译。想知道是否有人知道如何为 TI 实现这项功能?

据我所知,TI 使用 GCC 4.8.3。

顺便说一句,实际的类是一个模板,但我很确定这不是问题。

最佳答案

这不应该编译:编译器无法推断出 Member 的布局,因为它还没有解析整个 In 类。

只需声明嵌套的struct,并在 In 的定义之后定义它:

class In {
public:

struct Member;

In() {}

private:
static const int aCapacity = 16;
static const int oCapacity = 16;
};

struct In::Member{
In name;
};

关于c++ - 通过 TI 编译器使用定义类型的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25341764/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com