views:

171

answers:

2

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.

Do I have the right idea? or did I do something wrong?

+7  A: 

Do this:

#define DEFAULT_SIZE 10

The = sign is not needed in the preprocessor definition.

Greg Hewgill
+4  A: 

The #define line is wrong. You don't need the "=".

Anzurio