+ 4

Why there is no output?

class A{ public: A (){ cout <<"hi";} A (int a=0){ cout <<"hello";} }; int main() { A a(); } And if write like this A a; then there is an error....

27th Jan 2018, 6:23 PM
Nao
Nao - avatar
2 odpowiedzi
+ 2
I think there is no output because the compiler doesnt know which constructor he is supposed to call, since you specified a default value for the variable. It works if you remove the default value and either call the constructor without parentheses (first one) or with a value (second one).
27th Jan 2018, 6:51 PM
Shadow
Shadow - avatar
+ 1
int main() { A a(); } you declare a function "a" with return type "A" here e.g. check it out... int main() { A a(); a(); } A a(){ std::cout << " i am a function " << std::endl; }
27th Jan 2018, 9:35 PM
---
--- - avatar