Initialization
#include <iostream> | |
class B{ | |
public: | |
int a; | |
B():a(1){} | |
}; | |
class A{ | |
public: | |
B b; | |
A(B b):b(b){} | |
}; | |
int main(){ | |
A obj1(B()); | |
std::cout<< obj1.b.a; | |
// This might be a compiler error because obj1 gets | |
// interpreted as a declaration of a method. | |
A obj2( (B()) ); | |
std::cout<< obj2.b.a; | |
// With the extra set of parenthesis, this is correctly | |
// interpreted as the creation of an object of class A; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment