ISO C ++禁止声明无类型的“堆栈" [英] ISO C++ forbids declaration of 'Stack' with no type

查看:75
本文介绍了ISO C ++禁止声明无类型的“堆栈"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面有一个用于堆栈结构的头文件.我不明白的是此错误正在干扰我:

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 ++禁止声明无类型的'Stack'

ISO C++ forbids declaration of 'Stack' with no type

这是代码:

#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)应该是 Stack&运算符=(const Stack&).

您没有指向引用或引用数组的指针或任何其他内容,因此编译器认为& 必须终止声明的类型部分,并认为以下 Stack必须是参数名称.但是 const& 中没有类型,因此编译器说您不能声明没有类型的参数 Stack .在旧版本的C中,有时会在可能出现某种类型但又忽略了某种类型的上下文中推断出 int 类型,这就是为什么该错误谈到ISO C ++禁止这种情况的原因.

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. However there's no type in const& so the compiler says that you can't declare the parameter Stack with no type. 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.

这篇关于ISO C ++禁止声明无类型的“堆栈"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆