0
這裏是我的結構(這是數據結構類的私有部分):如何用空值初始化結構的數據成員數組?
private:
// this is the main node pointer array to keep
// track of buckets and its chain.
struct Node {
/** member variables */
unsigned int iCID;
std::string sVoting_PN;
std::string sTS[T_LITTRAL];
unsigned int iCounter[12] = {0};
/** constructor initializes */
Node(unsigned int CID, std::string PN, std::string TS, unsigned int counter, unsigned int index) {
this->iCID = CID;
this->sVoting_PN = PN;
this->sTS[index] = TS;
this->iCounter[CID] = iCounter[CID] + counter;
}
Node *next;
};
Node* nodeArray[TABLE_SIZE];
我想我該怎麼做,要iCounter陣列的所有值初始化爲0?
我想這一個
unsigned int iCounter[12] = {0};
,但它給我警告,我不得不刪除,無論如何!任何想法或幫助是非常感激的人。提前致謝。
明確你得到什麼警告?我得到無[在這縮短了測試(http://liveworkspace.org/code/e6e5a598130d40a3ac6a8c0322a3e219)(假定這就是你真正把'= {0}')。 – Xeo
@Xeo,這裏的warnigs是 ######################################### ##### 警告:只有-std = C++ 11或-std = gnu ++ 11可用的非靜態數據成員初始值設定項[默認情況下啓用] 警告:擴展初始值設定項列表僅適用於-std = C++ 11或-std = gnu ++ 11 [默認啓用] – johnshumon
那麼,爲什麼不編譯代碼時只包含...'-std = C++ 11'? – Xeo