Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++中的堆栈示例?_C++_Stack_Copy Constructor - Fatal编程技术网

C++中的堆栈示例?

C++中的堆栈示例?,c++,stack,copy-constructor,C++,Stack,Copy Constructor,这是一个直接取自本书的示例: template <class T> class stack { public: stack(); stack(const stack&); stack & operator=(const stack&); ~stack(); T& top(); void push(const T&); void pop(); //few more functions } 我有以下问题: 为什么top的返回类型不是stac

这是一个直接取自本书的示例:

template <class T>
class stack
{
public:
stack();
stack(const stack&);
stack & operator=(const stack&);
~stack();
T& top();
void push(const T&);
void pop();

//few more functions 

}
我有以下问题:

为什么top的返回类型不是stack&为什么重载赋值的参数不是T&

Rgds, 柔软的

为什么top的返回类型不是stack&


因为top的目的是返回堆栈顶部的元素,而不是堆栈本身

请重新措辞你的问题,并尝试使用句子。@VladLazarenko你是指拇指法则。。我知道它有缺陷!!第二部分是允许堆栈s,t,u;u=t=s;