Why is my overloaded C++ constructor not called?

前端 未结 6 1731
暖寄归人
暖寄归人 2021-02-20 12:17

I have a class like this one:

class Test{
public:
  Test(string value);
  Test(bool value);

};

If I create an object like this:



        
6条回答
  •  我寻月下人不归
    2021-02-20 13:21

    One way is to create a variable of type std::string and pass the variable in:

    std::string test = "TEST";
    A a(test);
    

    This way the type is explicitly defined as std::string it won't default to the constructor that accepts bool

提交回复
热议问题