Skip to content

Instantly share code, notes, and snippets.


jitpaul/initialization1.cpp Secret

Last active Apr 6, 2020
What would you like to do?
#include <iostream>
class B{
int a;
class A{
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