I have setup the following header file to create a Stack which uses an Array. I get the following at line 7:
error: ISO C++ forbids declaration of ‘Stack” with no type.
I thought the type was the input value. Appreciate your help. Thank you.
#ifndef ARRAYSTACKER_H_INCLUDED
#define ARRAYSTACKER_H_INCLUDED
// ArrayStacker.h: header file
class ArrayStack {
int MaxSize;
int EmptyStack;
int top;
int* items;
public:
Stacker(int sizeIn);
~Stacker();
void push(int intIn);
int pop();
int peekIn();
int empty();
int full();
};
#endif // ARRAYSTACKER_H_INCLUDED
The
error: ISO C++ forbids declaration of "identifier" with no type.error indicates that the declared type of identifier or identifier, itself, is a type for which the declaration has not been found.For example, if you wrote the following in your code:
The line above would give you such an error if you had failed to include the header in which “ArrayStack” is defined. You would also get such an error, if you accidentally used
Stackinstead ofArrayStack(e.g. when declaring a variable or when using it as function’s return-type, etc.). I should also point out that your header has a fairly obvious error that you probably want to correct; a class’s constructor and destructor must match the name of the class. The compiler is going to be confused, because when it sees “Stacker”, it is going to interpret it as a function named “Stacker” where you simply forgot to give it a return-type (it won’t realize that you actually meant for that to be the constructor, and simply mispelled it).