初始化没有默认构造函数的类

wro*_*ame 6 c++ oop constructor compiler-errors initialization

如果我有一个类A只有一个拷贝构造函数和一个带参数的构造函数intint,和我把一个类内部的类B:

class B
{
public:
    B();
private
    A a;
}
Run Code Online (Sandbox Code Playgroud)

我如何a在B的构造函数中初始化?

我已经尝试了a(0, 0),a = A(0, 0)但并不奇怪也没有奏效,我收到了

error: no matching function for call to ‘A::A()’
Run Code Online (Sandbox Code Playgroud)

Sta*_*key 13

在B的构造函数中,你会做这样的事情:

B::B() : a(0, 0)
{
    // ctor here
}
Run Code Online (Sandbox Code Playgroud)