ISO C++禁止声明“Stack”没有类型

发布于 2024-08-29 10:21:06 字数 525 浏览 1 评论 0原文

我已经设置了以下头文件来创建一个使用数组的堆栈。我在第 7 行得到以下信息:

错误:ISO C++ 禁止声明没有类型的“Stack”。

我认为该类型是输入值。感谢您的帮助。谢谢。

#ifndef ARRAYSTACKER_H_INCLUDED
#define ARRAYSTACKER_H_INCLUDED
// ArrayStacker.h: header file
class ArrayStack {
    int MaxSize;
    int EmptyStack;
    int top;
    int* items;
public:
    Stacker(int sizeIn);
    ~Stacker();
    void push(int intIn);
    int pop();
    int peekIn();
    int empty();
    int full();
};
#endif // ARRAYSTACKER_H_INCLUDED

I have setup the following header file to create a Stack which uses an Array. I get the following at line 7:

error: ISO C++ forbids declaration of 'Stack" with no type.

I thought the type was the input value. Appreciate your help. Thank you.

#ifndef ARRAYSTACKER_H_INCLUDED
#define ARRAYSTACKER_H_INCLUDED
// ArrayStacker.h: header file
class ArrayStack {
    int MaxSize;
    int EmptyStack;
    int top;
    int* items;
public:
    Stacker(int sizeIn);
    ~Stacker();
    void push(int intIn);
    int pop();
    int peekIn();
    int empty();
    int full();
};
#endif // ARRAYSTACKER_H_INCLUDED

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒中人 2024-09-05 10:21:06

构造函数和析构函数具有类的名称,即 ArrayStack,而不是 Stacker。

The constructor and destructor have the name of the class, which is ArrayStack, not Stacker.

吲‖鸣 2024-09-05 10:21:06

错误:ISO C++ 禁止声明没有类型的“identifier”。错误表示声明的 identifieridentifier< 类型/i> 本身是一种尚未找到其声明的类型。

例如,如果您在代码中编写了以下内容:

ArrayStack Stack;

如果您未能包含定义“ArrayStack”的标头,则上面的行将给出这样的错误。如果您不小心使用了 Stack 而不是 ArrayStack(例如,在声明变量时或将其用作函数的返回类型等时),您也会收到这样的错误。我还应该指出,您的标头有一个相当明显的错误,您可能想要更正;类的构造函数和析构函数必须与类的名称匹配。编译器会感到困惑,因为当它看到“Stacker”时,它会将其解释为名为“Stacker”的函数,而您只是忘记给它一个返回类型(它不会意识到您实际上的意思因为它是构造函数,只是拼写错误)。

The error: ISO C++ forbids declaration of "identifier" with no type. error indicates that the declared type of identifier or identifier, itself, is a type for which the declaration has not been found.

For example, if you wrote the following in your code:

ArrayStack Stack;

The line above would give you such an error if you had failed to include the header in which "ArrayStack" is defined. You would also get such an error, if you accidentally used Stack instead of ArrayStack (e.g. when declaring a variable or when using it as function's return-type, etc.). I should also point out that your header has a fairly obvious error that you probably want to correct; a class's constructor and destructor must match the name of the class. The compiler is going to be confused, because when it sees "Stacker", it is going to interpret it as a function named "Stacker" where you simply forgot to give it a return-type (it won't realize that you actually meant for that to be the constructor, and simply mispelled it).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文