+ 2

How does this code work?

Why there is no output? #include <iostream> using namespace std; class A { public: A() { cout << "Class A!"; } A(int a = 0) { cout << "A"; } }; int main() { A a(); } https://code.sololearn.com/ctnrvYPt2n6D/#cpp

6th Mar 2022, 8:56 AM
wave rider
wave rider - avatar
1 Answer
+ 1
I think A a() does not even call the constructor at all and should've failed the compilation step. So a() in this case is removed from the final executable.
6th Mar 2022, 6:46 PM
wave rider
wave rider - avatar