【发布时间】:2016-10-18 18:51:26
【问题描述】:
我为std::stack 创建了一个堆栈扩展。
我已经创建了一个模板类,它的代码在这里:
template<class _StackType>
class Stack
{
std::stack<_StackType> data_container;
mutable std::mutex M;
public :
Stack(const Stack& other)
{
std::lock_guard<std::mutex> lock(other.M);
this->data_container = other.data_container;
}
但是当我初始化它时:
Stack<int> myStack;
它会抛出以下错误:
error: no matching function for call to `‘Stack<int>::Stack()’`
运营商好像有问题。我确实尝试过创建运算符重载,但尝试失败。
错误的原因是什么?
【问题讨论】:
-
没有运营商参与??您只是错过了指定默认构造函数。如果定义了复制构造函数,编译器不会自动生成一个。
标签: c++ class default-constructor