Feel free to edit the title I'm not sure how to phrase this.
I'm trying to figure out how to call a class's constructor other than the default when it is instantiated in another class. What I mean is this...
class A
{
public:
A(){cout << "i get this default constructor when I create a B" << endl;}
A(int i){cout << "this is the constructor i want when I create a B" << endl;}
};
class B
{
A a;
};
int main()
{
B *ptr = new B;
return 0;
}
I've done some searching but I don't see a way to do what I want. I thought maybe in B's declaration I could do A a(5)
but that doesn't work.
Thanks