-4
我試圖編譯.c文件,其中包括相應的.h這樣一個ISO C++編譯錯誤的C代碼
typedef struct myType
{
char* myString = "NOT SET";
int myInt = -1;
}
運行「GCC -c myfile.c文件」引發了以下錯誤時, :
Error: ISO C++ forbids initialization of member 'myString'
Error: making 'myString' static
Error: invalid in-class initialization of static data member of non-integral type ‘char*’
Error: ISO C++ forbids initialization of member 'myInt'
Error: making 'myInt' static
Error: invalid in-class initialization of static data member of non-integral type ‘int’
所以我的問題是雙重的:首先,我爲什麼不能初始化值在我的頭的結構?其次,爲什麼我在編譯C代碼時遇到ISO C++錯誤?
C或C++?包括你展示C++ btw的爭論。 – Deduplicator 2014-10-08 14:36:59
請創建一個[最小工作示例](http://stackoverflow.com/help/mcve)/ [備用](http://sscce.org/)。 – Unapiedra 2014-10-08 14:39:15
像這樣在'struct'中初始化東西是否合法?我認爲這是合法的,因爲C++ 11 ... – GingerPlusPlus 2014-10-08 15:01:41