Summit
Summit

Reputation: 2268

The value of boolean variable intialized in a class

In my Class i have a boolean variable

class Sum_SystemTagControlVisitor : public FunctionVisitor
{
private:
    std::string variableName;
    std::string variableValue;
    std::string variableValue1;
    bool m_bIsTimer{ false };
public:
    Sum_SystemTagControlVisitor(std::string varName, std::string varValue ) : variableName(varName), variableValue(varValue) { }
    Sum_SystemTagControlVisitor(std::string varName, std::string varValue , bool isTimer) : variableName(varName), variableValue(varValue) , m_bIsTimer(isTimer){ }
    Sum_SystemTagControlVisitor(std::string varName, std::string varValue, std::string varValue1) : variableName(varName), variableValue(varValue), variableValue1(varValue1) { }
    virtual void visit(Sum_TagControl& tagControl ) override;

};

Only one of the constructor is able to set the boolean value and for the other two constructors will it be always be false ?

Upvotes: 2

Views: 55

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409146

Inline initialization of member variables will always take place, unless your initializer list contains an entry for that variable.

So in short: For the constructor that doesn't initialize the variable, it will be automatically initialized to false.

Upvotes: 1

Related Questions