简体   繁体   English

错误:ISO C ++禁止无类型的声明

[英]error: ISO C++ forbids declaration of '' with no type

I got error: ISO C++ forbids declaration of 'InvalidSig' with no type of the below header file, how to solve it? 我收到error: ISO C++ forbids declaration of 'InvalidSig' with no type以下头文件的error: ISO C++ forbids declaration of 'InvalidSig' with no type ,如何解决?

struct args{
    InvalidSig* context; //error
    string mname;
};

class InvalidSig{
    .......
}

You can forward declare class InvalidSig above: 您可以在上面转发声明class InvalidSig

class InvalidSig;

struct args {
    InvalidSig* context;
    // ...
};

You can also do this, if you only want to use the name once before its definition: 如果只想在名称定义之前使用一次,也可以执行以下操作:

struct args {
    class InvalidSig* context;
    // ...
};

I recommend avoiding the latter though, as the former is more common and will be less confusing to anyone reading your code. 但我建议避免使用后者,因为前者更为常见,并且对阅读您的代码的人不会造成混淆。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM