Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initializing class without default constructor

If I have a class A with only a copy constructor and a constructor with parameters int and int, and I place that class inside a class B:

class B
{
public:
    B();
private
    A a;
}

How would I initialize a inside B's constructor?

I've tried a(0, 0), a = A(0, 0), but not surprisingly neither worked, and I receive a

error: no matching function for call to ‘A::A()’
like image 946
wrongusername Avatar asked Sep 13 '10 21:09

wrongusername


1 Answers

In B's constructor, you would do something like this:

B::B() : a(0, 0)
{
    // ctor here
}
like image 193
Starkey Avatar answered Oct 19 '22 01:10

Starkey