I keep getting this error code when trying to compile.
1 2 3 4 5 6 7 8 9 10 11 12 13
In file included from prog6.cpp:10:
Stack.h:21: error: `ItemType' has not been declared
Stack.h:21: error: ISO C++ forbids declaration of `item' with no type
Stack.h:23: error: `ItemType' does not name a type
Stack.h:27: error: `ItemType' does not name a type
prog6.cpp: In function `int main()':
prog6.cpp:39: error: 'class StackType' has no member named 'Top'
In file included from Stack.cpp:11:
Stack.h:21: error: `ItemType' has not been declared
Stack.h:21: error: ISO C++ forbids declaration of `item' with no type
Stack.h:23: error: `ItemType' does not name a type
Stack.h:27: error: `ItemType' does not name a type
In file included from prog6.cpp:10:
Stack.h:28: error: `MAX_ITEMS' was not declared in this scope
prog6.cpp: In function `int main()':
prog6.cpp:20: error: missing template arguments before "stack"
prog6.cpp:20: error: expected `;' before "stack"
prog6.cpp:30: error: `stack' was not declared in this scope
prog6.cpp:34: error: `stack' was not declared in this scope
In file included from Stack.cpp:11:
Stack.h:28: error: `MAX_ITEMS' was not declared in this scope
Stack.cpp:14: error: `template<class ItemType> class StackType' used without template parameters
Stack.cpp:16: error: ISO C++ forbids declaration of `StackType' with no type
Stack.cpp: In function `int StackType()':
In file included from prog6.cpp:2:
Stack.h:6: error: expected constructor, destructor, or type conversion before '<' token
Stack.h:16: error: expected constructor, destructor, or type conversion before '<' token
Stack.h:32: error: expected constructor, destructor, or type conversion before '<' token
Stack.h:39: error: expected initializer before '<' token
Those are the only errors i get when i call the function.
I think you got . and .cpp swapped. In either case, when dealing with templated classes the definitions of the functions need to be in the same file as the definition of the class. Also I think you keep forgetting to copy the }; at the end of your StackType class.
As for the errors, in the code that in your post you marked .h file, you have no body for the functions. Meaning, you forgot the curly braces {}