errors in compiling

Discussion in 'C++' started by elsa87, Nov 18, 2008.

  1. elsa87

    elsa87 New Member

    Joined:
    Oct 10, 2008
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    0
    hello everyone
    i have a problem with the below code
    it gives me that there are 5 errors:

    Compiling...
    asdfsa.cpp
    c:\documents and settings\ahmed aburumman\desktop\ljdf\asdfsa.cpp(9) : error C2258: illegal pure syntax, must be '= 0'
    c:\documents and settings\ahmed aburumman\desktop\ljdf\asdfsa.cpp(9) : error C2252: 'MAX' : pure specifier can only be specified for functions
    c:\documents and settings\ahmed aburumman\desktop\ljdf\asdfsa.cpp(10) : error C2065: 'MAX' : undeclared identifier
    c:\documents and settings\ahmed aburumman\desktop\ljdf\asdfsa.cpp(10) : error C2057: expected constant expression
    c:\documents and settings\ahmed aburumman\desktop\ljdf\asdfsa.cpp(10) : warning C4200: nonstandard extension used : zero-sized Array in struct/union
    c:\documents and settings\ahmed aburumman\desktop\ljdf\asdfsa.cpp(11) : error C2229: Class 'stack' has an illegal zero-sized Array
    Error executing cl.exe.

    asdfsa.obj - 5 error(s), 1 warning(s)

    Can somebody help?(im using a microsoft visual c++ 6.0 compiler if this means anything)
    Code:
    
    #include <iostream>
    #include<cstdlib>
    #include<ctime>
    using namespace std;
    class stack
    {
    private:
            static const int MAX=10;  
            int st[MAX];
            int top;
            public:
                   stack():top(-1){}
                   void push(int v){st[++top]=v;}
                   int pop(){return st[top--];}
                   bool isempty(){return (top==-1);}  
                   bool isfull(){return top==MAX-1;}
                   void print()
                   {
                   while(!isempty())
                   cout<<pop()<<endl;
                   }
                   void print_reve()
                   {
                   int i=0;     
                   while(i!=MAX)
                   cout<<st[i++]<<endl;     
                   }
    };
    int main(int argc, char *argv[])
    {  
    srand(time(0));    
    stack s;
    while(!s.isfull()) 
    s.push(rand()%1000+1);
    s.print();
    cout<<"--------\n";
    s.print_reve();
    cin.get();
        return 0;
    }
     
    
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Must be a compiler bug. It doesn't like "static const int MAX=10;", but it seems OK to me, and it compiles OK in Visual Studio 2005.
     
  3. elsa87

    elsa87 New Member

    Joined:
    Oct 10, 2008
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    0
    mmmm
    i downloaded visual c++ 2008 and i didnt even know how to run the program..
    could u plz send me a screen shot of the program when executed?
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    There's nothing to give you a screen shot of; I only included enough in the code to test the MAX definition. The following code compiled in VS2005, and ran:
    Code:
    class stack
    {
    private:
    	static const int MAX=10;  
    	int st[MAX];
    	int top;
    public:
    	stack():top(-1){}
    };
    
    void go4e_15170()
    {
    	stack foo;
    }
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice