0

I have the next class and want to initialize _operators array with 0:

    //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]
{

}

I thought this sold work in C++ v11 but i got error... how can i initialize array with 0.. with ugly for? i don't want make it static

4
  • 2
    You forgot the trailing () on your array initializer, and you don't need the dimensions there; only in the decl. I.e. ` : _operator()`. sidenote: terrible name for a member var. Commented Sep 8, 2013 at 8:58
  • why is it terrible (in that array there are values of operators +, -, /) etc? Commented Sep 8, 2013 at 9:07
  • In a language that is often littered with the word operator, you can surely call it something else (op springs to my mind). Commented Sep 8, 2013 at 9:11
  • It makes senth.. there is probability of conflict but i care more abaut logic and objective clearness than abaut potential conflict... I don't think that somewhere there is public type "_operators"... And my _operators is private. I take a risk. Commented Sep 8, 2013 at 9:25

1 Answer 1

6

You just need to value-initialize the array:

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

This works in C++03 and C++11.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 (obviously) And note, even now MS "warns" that this is an extension for C++0x3 and later (and then proceeds to do the right thing anyway, go figure). =P

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.