template <class Type> class Queue {
Queue(): head(0), tail(0) {
cout << "Queue--default constructor called" << endl;
}
Queue(const Queue &Q): head(0), tail(0) {
cout << "Queue--copy constructor called" << endl;
//...
}
Queue& operator=(const Queue&) {
cout << "Queue--operator= called" << endl;
//...
}
~Queue() { //... }
private:
QueueItem<Type> *head;
QueueItem<Type> *tail;
};
我已经定义了一个模板类Queue
并尝试了以下代码:
Queue<char*> cq;
Queue<char*> ccq(cq);
Queue<char*> acq = cq;
Queue<char*> acq2;
acq2 = cq;
输出是:
Queue--default constructor called
Queue--copy constructor called
Queue--copy constructor called
Queue--default constructor called
Queue--operator= called
让我困惑的是代码Queue<char*> acq = cq;
调用了复制构造函数Queue--copy constructor called
,但没有default constructor and operator=
调用要调用的。
任何人都可以帮助我吗?
谢谢你考虑我的问题!