Suppose I have a class
class C {
C(int a=10);
};
why if I call
C c;
the contructor C(int =10)
is called and if I call
C c();
the default constructor is called? How to avoid this? I want to execute only my constructor, I tried to make the default constructor private, but it doesn't work.
C c();
should be parsed as a function declaration. In order to explicitly invoke the default-constructor, you need to write C c = C();
.explicit
, to prevent implicit conversions from kicking in at unexpected moments. If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With