views:

257

answers:

2

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
1.  class ArrayStack {
2.     int MaxSize;
3.     int EmptyStack;
4.     int top;
5.     int* items;
6.  public:
7.     Stacker(int sizeIn);
8.     ~Stacker();
9.     void push(int intIn);
10.    int pop();
11.    int peekIn();
12.    int empty();
13.    int full();
14.  };
#endif // ARRAYSTACKER_H_INCLUDED
+9  A: 

The constructor and destructor have the name of the class, which is ArrayStack, not Stacker.

GMan
Yeah, fix the constructor name and see if you still get the error... If you do continue to get the error, then post your constructor implementation.
advs89
Resolved!! Thank u.
JDragon314159
+2  A: 

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:

ArrayStack Stack;

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 Stack instead of ArrayStack (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).

Michael Aaron Safyan
Yes. Thank you. I was confused with the convention of not using the file name for the class name which is unlike Java. But the class was not the file name goofed it. Oops! Good answer.
JDragon314159
@JKid, your welcome. Also, please show your appreciation by upvoting.
Michael Aaron Safyan
ok. upvote? gotta figure it out and then do it. thanks for letting me know.
JDragon314159