简体   繁体   English

堆栈上的 C++ 编程书籍示例

[英]C++ Programming Book Example on Stack

In this book, I am learning how the book writes a stack, but when I compile it, it reaches a compile error:在这本书中,我正在学习这本书如何编写堆栈,但是当我编译它时,它遇到了编译错误:

#define DEFAULT_SIZE = 10

class Stack
{
    private:
        int size;
        int top;
        int *value;

    public:
        Stack( int size = DEFAULT_SIZE );
        virtual ~Stack();
        bool isFull();
        bool isEmpty();
        void push(int);
        int pop();
};

and the errors indicates:并且错误表明:

C:\Documents and Settings\Eddy\Desktop\C++ Playground\Data Structures\stack.h|14|error: expected primary-expression before '=' token|
||=== Build finished: 1 errors, 0 warnings ===|

I am using Code::Blocks as my IDE, and I believe that you cant initlize inside a class, and to create a "DEFAULT_SIZE" would be commonly in a default constructor.我使用 Code::Blocks 作为我的 IDE,我相信你不能在类中初始化,并且创建“DEFAULT_SIZE”通常在默认构造函数中。

Do I have the right idea?我有正确的想法吗? or did I do something wrong?还是我做错了什么?

Do this:做这个:

#define DEFAULT_SIZE 10

The = sign is not needed in the preprocessor definition.预处理器定义中不需要=符号。

The #define line is wrong. #define行是错误的。 You don't need the equals symbol = .您不需要等号=

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM