Skip to content

Instantly share code, notes, and snippets.

Created August 13, 2016 19:16
#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