定義結構體時初始化成員的方式


當定義如下結構體時

struct Node{
int exp=0;
int coe=0;

};

 

編譯器出現如下警告:
[Warning] non-static data member initializers only available with -std=c++11 or -std=gnu++11
 
修改如下所示,可以消除警告:

struct Node{
int exp;
int coe;
Node():exp(0),coe(0){
}
};

c++primer plus好像有提過這一點。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM