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; }
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.
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?
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; }