【发布时间】:2022-01-05 12:51:13
【问题描述】:
class Q
{
Q(const Q &obj) {} // copy constructor
Q& operator= (const Q& a){} // equal op overload
}
template <class T>
class B{
public : T x;
B<T>(T t) {
// x = t; }
}
int main()
{
Q a(2);
a.init(1,0);
a.init(2,1);
B <Q> aa(a); // this line gives error
}
如何使用复制构造函数初始化模板类?咩(a); // 这行给出错误 我想解决它,但我不能。 错误:
没有匹配函数调用'Q::Q()'| 候选人:Q::Q(const Q&)|
候选人期望 1 个参数,提供 0 个| 候选人:Q::Q(int)|
候选人期望 1 个参数,提供 0 个|
【问题讨论】:
标签: c++ copy-constructor template-classes