Calling the constructor of another class through an initialization list. Problems

This is my sample code:

#include <iostream>
using namespace std;

class Base
{
public:
    Base (int v, char z) {x=v;y=z;};
    int x;
    char y;
};

class Bar
{
public:
    Bar(int m, char n):q(m),s(n),base(q,s){};
    Base base;
    int q;
    char s;    
};

int main()
{
    Bar barObj(5,'h');    
    cout << barObj.base.x << barObj.base.y << endl;       
    return 0;
}

Why am I getting a conclusion 0? http://ideone.com/pf47j

In addition, in general, what is the correct method for creating a member object in another class and calling the constructor of this object, as was done above with the database of objects class Baseinside class Bar?

+5
source share
1 answer

, , . , Bar::base Bar::q Bar::s.
http://ideone.com/M6iKR, Bar::Bar(int m, char n) base m n .

+6

All Articles