[英]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
: 如果我有一个只有复制构造函数的
A
类和一个带参数int
和int
的构造函数,我将该类放在一个B
类中:
class B
{
public:
B();
private
A a;
}
How would I initialize a
inside B's constructor? 我将如何初始化
a
内部B的构造函数?
I've tried a(0, 0)
, a = A(0, 0)
, but not surprisingly neither worked, and I receive a 我已经尝试
a(0, 0)
, a = A(0, 0)
,但不出意外都没有奏效,我收到了
error: no matching function for call to ‘A::A()’
In B's constructor, you would do something like this: 在B的构造函数中,你会做这样的事情:
B::B() : a(0, 0)
{
// ctor here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.