Created
August 13, 2016 19:16
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
class Bar { | |
public: | |
int i; | |
/* constructor with an agrument to init i to */ | |
Bar(int new_i) : i(new_i) { | |
} | |
}; | |
class Foo { | |
public: | |
int data; | |
Bar bar; | |
/* default constructor: init data to zero */ | |
Foo(): bar(3), data(0) { | |
} | |
}; | |
using namespace std; | |
int main() { | |
Foo obj1; // default constructor | |
cout << obj1.data << endl; | |
cout << obj1.bar.i << endl; | |
return 0; | |
} | |
/* output | |
0 | |
3 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment