![](/img/trans.png)
[英]C++ Struct and “error: ISO C++ forbids declaration of '…' with no type”
[英]error: ISO C++ forbids declaration of '' with no type
我收到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{
.......
}
您可以在上面轉發聲明class InvalidSig
:
class InvalidSig;
struct args {
InvalidSig* context;
// ...
};
如果只想在名稱定義之前使用一次,也可以執行以下操作:
struct args {
class InvalidSig* context;
// ...
};
但我建議避免使用后者,因為前者更為常見,並且對閱讀您的代碼的人不會造成混淆。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.