[英]ISO C++ forbids declaration of 'Stack' with no type
I have below a header file for a stack structure. 我下面有一个用于堆栈结构的头文件。 what I don't understand is this error it is jamming at me: 我不明白的是这个错误正在困扰我:
ISO C++ forbids declaration of 'Stack' with no type ISO C ++禁止声明无类型的“堆栈”
Here's the code : 这是代码:
#include <stdexcept>
class Element;
class Stack{
public:
Stack():first(0){}; //constructor
~Stack(); //destructor
void push(int d);
int pop()throw(length_error);
bool empty();
private:
Element *first;
Stack(const& Stack){}; //copy constructor
Stack& operator = (const& Stack){}; //assignment operator..
};
does anyone have a clue what the error means? 有人知道错误是什么意思吗?
Stack& operator = (const& Stack)
should be Stack& operator = (const Stack&)
. Stack& operator = (const& Stack)
应为Stack& operator = (const Stack&)
。
You can't have a pointer to a reference or an array of references or anything so the compiler thinks that &
must end the type part of the declaration and that the following Stack
must be the parameter name. 您没有指向引用或引用数组的指针或任何内容,因此编译器认为&
必须以声明的类型部分结尾,并且以下Stack
必须为参数名称。 However there's no type in const&
so the compiler says that you can't declare the parameter Stack
with no type. 但是const&
没有类型,因此编译器说您不能声明没有类型的参数Stack
。 In old versions of C the type int
was sometimes inferred in contexts where a type could appear but was omitted which is why the error talks about ISO C++ forbidding this. 在旧版本的C中,有时会在可能出现某种类型但又忽略了某种类型的上下文中推断出int
类型,这就是为什么错误提到ISO C ++禁止这样做的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.