i've been working on this program for a couple days now, while doing some research on classes. heres my code so far, its giving me about 10 erros.
Quote
15 C:\Documents and Settings\Andrew\My Documents\C++\Stack\stack.cpp ISO C++ forbids declaration of `push' with no type
Quote
34 C:\Documents and Settings\Andrew\My Documents\C++\Stack\stack.cpp prototype for `int STACK::push(int)' does not match any in class `STACK'
Quote
73 C:\Documents and Settings\Andrew\My Documents\C++\Stack\stack.cpp no matching function for call to `STACK::STACK(int&)'
heres the code:
it would be greatly appreciated if someone could point me in the right direction as to what im doing wrong. those three errors occur more than once so its oviously something im repetedly doing wrong. thanks!
#include<iostream.h>
#include<fstream.h>
#include"apstring.h"
#include"apvector.h"
#include"apstring.cpp"
class STACK
{
private:
int top, stack[20];
public:
STACK();
push();
pop(int x);
int current ()
{
return top;
}
};
STACK::STACK()
{
top=-1;
for(int i=0;i<20;i++)
{
stack[i]=0;
}
}
STACK::push (int x)
{
top++;
stack[top] = x;
}
int STACK::pop ()
{
top--;
int x = stack[top];
return x;
}
//Main
int main ()
{
int pushnum;
apstring choice;
STACK a;
do{
cout<<"Enter 'push', 'pop', or 'q': ";
cin>>choice;
if(choice == "q")
{
system("PAUSE");
}
if(choice == "pop")
{
STACK pop();
cout<<"Current number is: "<<a.current();
}
if(choice == "push")
{
cout<<"\n\nEnter number to push: ";
cin>>pushnum;
STACK push(pushnum);
cout<<"\n\nCurrent number is: "<<pushnum;
}
}while(choice != "q");
system("PAUSE");
return 1;
}
This post has been edited by Dark_Nexus: 29 March 2006 - 10:13 AM

New Topic/Question
Reply



MultiQuote



|