C++队列模板STL
我有默认构造函数,但复制构造函数有问题。任何帮助C++队列模板STL,c++,templates,queue,C++,Templates,Queue,我有默认构造函数,但复制构造函数有问题。任何帮助 enum Direction { front_to_back, back_to_front }; template <typename EType> class Queue { private: struct Node { EType Item; unsigned Priority; unsigned Identifier; Node * Pred;
enum Direction { front_to_back, back_to_front };
template <typename EType>
class Queue
{
private:
struct Node
{
EType Item;
unsigned Priority;
unsigned Identifier;
Node * Pred;
Node * Succ;
};
Node * Head; // Pointer to head of chain (front)
Node * Tail; // Pointer to tail of chain (back)
public:
// Initialize pqueue to empty
//
Queue();
// De-initialize pqueue
//
~Queue();
// Re-initialize pqueue to empty
//
void reset();
// Initialize pqueue using existing pqueue
因为您在这里使用的是原始指针,所以希望禁用复制构造和分配,以避免双重删除问题和内存泄漏。这可以通过以下方式实现:
private: // note that these are not implemented
Queue( const Queue& );
Queue& operator=( const Queue& );
或者通过继承。您在编写复制构造函数时遇到问题,还是想禁用复制构造函数?这与STL有什么关系?请详细说明您遇到的问题。目前,我在复制构造函数方面遇到问题。我已经解决了析构函数的原始问题,你的计划是在这里针对作业中的每个方法提问,而不是针对你所问的方法显示任何尝试过的代码吗?如果是这样,那不是一个很好的计划。嗯,我不允许那样做。重置不会做同样的事情吗?你认为你的副本构建/任务应该做什么?队列的完整深度副本?参考计数?什么?我指的是毁灭者。