mercredi 4 mai 2016

Value of primitive member in constructor [duplicate]

This question already has an answer here:

Suppose I have the following class:

class Foo{
public:
    Foo(){
        std::cout << bar_;
    }

private:
    int bar_;
};

Is this guaranteed to always output 0?

In other words - is an int member always initialized to 0 before the constructor is executed, if no initializer list is used?

I'm asking because I'm getting a weird error in a project I'm working on, where a private int member has the value 32767 at the beginning of a constructor under certain circumstances (which involves too much code and dependencies to post here).

Aucun commentaire:

Enregistrer un commentaire