Xcode shows MAX as an undeclared identifier

Hello,

VS 13 in Windows can run the following program without any error message whereas Xcode in Mac shows "use of undeclared identifier 'MAX' " at line 43 in the following program.

Can someone explain what is going on with Xcode?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef STACK_H  // multiple inclusion guard
#define STACK_H
#include <iostream>
#include <algorithm>

using namespace std;

namespace Stack_ns // stack namespace
{
    const size_t CAPACITY = 30;
    template <class Item>
    class Stack
    {
    public:
        Stack();
        // MUTATORS
        void push(const Item & entry);
        void pop();
        // ACCESSORS
        bool empty() const; 
        bool isfull() const; 
        size_t size() const; 
        Item top() const; 
    private:
        Item data[CAPACITY]; // static array container
        size_t tos; // Top Of Stack
    };
    
    
    template <class item>
    Stack<item>::Stack()
    {
        tos = 0;
    }
    template <class item>
    bool Stack<item>::empty() const 
    {
        return (tos == 0);
    }
    template <class item>
    bool Stack<item>::isfull() const
    {
        return (tos == MAX);
    }
    template <class item>
    void Stack<item>::push(const item & entry)
    {
        if (tos < CAPACITY)
            data[tos++] = entry; 
        else
            cout << "Overflow!\n";
    }
    template <class item>
    void Stack<item>::pop()
    {
        if (tos > 0)
            --tos; 
        else
            cout << "Underflow!\n";
    }
    template <class item>
    item Stack<item>::top() const
    {
        return data[tos - 1];
    }
    template <class item>
    size_t Stack<item>::size() const
    {
        return tos;
    }
}
#endif 
Last edited on
MAX is not defined anywhere in the code you've posted nor in the standard headers you've included.
What do you expect the value of MAX to be?
Last edited on
Hi helios,

Thank you for your reply.

I am not sure what MAX should be in this program (because my professor did not specify its meaning in his lecture), but what is the meaning of MAX in the standard header we suppose to include here, and what is name of that standard header?
There is no MAX in any standard C++ header.
Your professor made a mistake; you need to correct it.
1
2
3
4
5
    bool Stack<item>::isfull() const
    {
            // return (tos == MAX);
            return tos == CAPACITY;
    }
Hi JLBorges,

I appreciate for your help. Now program runs in Xcode too :)

Why then did this code work smoothly in VS13?
Some header included somewhere defined the symbol 'MAX'. Probably a Windows header that defines it as a macro.
Topic archived. No new replies allowed.