如何用0初始化类成员数组

Bra*_*ans 0 c++ arrays initialization

我有下一个类,并希望用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]
{

}
Run Code Online (Sandbox Code Playgroud)

我以为这是在C++ v11中出售的工作,但是我得到了错误...我怎么能用0来初始化数组..丑陋的?我不想让它静止

jua*_*nza 6

您只需要初始化数组:

Entity::Entity() : _operators() {}
//                           ^^
Run Code Online (Sandbox Code Playgroud)

这适用于C++ 03和C++ 11.