ISO C ++ forbids declaring "Stack" without a type

I created the following header file to create a Stack that uses Array. I get the following on line 7:

error: ISO C ++ forbids declaring "Stack" without a type.

I thought the type is the input value. Appreciate your help. Thanks.

#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

      

+2


a source to share


2 answers


The error indicates that the declared type identifier, or identifier itself, is a type for which no declaration was found.error: ISO C++ forbids declaration of "identifier" with no type.

For example, if you wrote the following in your code:



ArrayStack Stack;

The above line will give you this error if you were unable to include the header in which the "ArrayStack" is defined. You will also get an error like this if you accidentally use Stack

instead ArrayStack

(for example, when declaring a variable, or when using it as a return-type function, etc.). I should also point out that your title has a fairly obvious error that you probably want to fix; the class constructor and destructor must match the class name. The compiler will get confused because when it sees "Stacker" it will interpret it as a function named "Stacker" where you just forgot to give it a return type (it won't understand what you actually meant to be a constructor , and just misused it).

+7


a source


The constructor and destructor have a class name that is ArrayStack

not Stacker

.



+11


a source







All Articles