【问题标题】:Using a member of the defined type with the TI compiler在 TI 编译器中使用定义类型的成员
【发布时间】:2014-08-16 16:30:38
【问题描述】:

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

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 工作?

AFAIK,TI 使用 GCC 4.8.3。

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

【问题讨论】:

    标签: c++ texas-instruments


    【解决方案1】:

    这不应该编译:编译器无法推断出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;
     };
    

    【讨论】:

    • 感谢您的快速回复。虽然这解决了所描述的问题,但它显然只有在成员的名称成员(需要为我的示例选择更好的名称)不能在类 In 中的任何地方引用时才有效。这个问题的有趣之处在于微软编译器确实编译了这个。我认为这是因为它进行了多次编译。如果没有提供更好的答案,我会将其标记为答案,但我想等待其他回复。
    • @PatrickO'Hara : 可以,只要定义需要使用Member的函数struct In::Member { ... }的定义之后
    • 我确信这会起作用,我最终将它们更改为指针,这显然也解决了问题。
    猜你喜欢
    • 2011-07-08
    • 2015-10-24
    • 2023-03-23
    • 2018-04-30
    • 2018-01-04
    • 1970-01-01
    • 2011-09-23
    • 2012-01-27
    • 2022-07-11
    相关资源
    最近更新 更多