簡體   English   中英

如何用0初始化類成員數組

[英]How to initialize class member array with 0

我有下一個類,想用0初始化_operators數組:

    //Entity.h
class Entity
{
    static const unsigned short operatorTypeColumn = 1;
    static const unsigned short outputValueColumn = 4;
private:
    mainDataType _operators[operatorsMaxCount][operatorsTableWidth];
    }

    //Entity.cpp.          I thought this should work in C++ v11
Entity::Entity(void) : _operators[operatorsMaxCount][operatorsTableWidth]
{

}

我以為這是在C ++ v11中出售的作品,但是我遇到了錯誤...我如何用0 ..來初始化數組? 我不想讓它靜態

您只需要對數組進行值初始化:

Entity::Entity() : _operators() {}
//                           ^^

這適用於C ++ 03和C ++ 11。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM