Avoiding implicit conversion in constructor. The 'explicit' keyword doesn't help here

前端 未结 7 2057
闹比i
闹比i 2020-12-29 18:07

I am able to avoid the implicit conversion of a constructor using the explicit keyword. So now, conversions like A a1 = 10; can be avoided.

7条回答
  •  情深已故
    2020-12-29 18:24

    I just want to add that the A(double) = delete is a C++11 addition.

    If for whatever reason you cannot use this relatively new construct, you can simply declare it as private as this:

    class A{
      public:
        A(int);
      private:
        A(double);
    }
    

提交回复
热议问题