I am attempting to convert a class to a template class, I am confused how to call from the declaration of the template class from the function. If anyone has some advice or examples that would help me better understand what I need to be doing. I already looked on Google and thought it was helping but I don't think it fully applies to my situation.
If you use FiniteStack<float> there will be some errors. As such you can not use a float as an index for an array.
1 2 3 4 5 6 7
C & top; // this shouldn't be a reference, and should be of type uint (not C)
C size() const; // should return uint (unsigned int)
FiniteStack(C size); // should take parameter of uint (not C)
also:
1 2 3 4
if (top == 0) returntrue;
elsereturnfalse;
This is redundant, using a if statement to check a condition just to return the same condition.
I thought the whole point of a template class was so that you could define an element with type "T" or whatever you choose when initializing the template, and then you could stack variables with that template variable and then later declare it as a unit type, such as, int or string.
thanks for your help spaggy and xerzi, my compiler is taking everything except the StackEmptyException and StackFullException. When I attmpt to build it returns the following errors:
1>c:\users\ryan\documents\visual studio 11\projects\programming ii\prog07-part1\prog07-part1\main.cpp(52): error C2065: 'StackEmptyException' : undeclared identifier
1>c:\users\ryan\documents\visual studio 11\projects\programming ii\prog07-part1\prog07-part1\main.cpp(52): error C2316: 'FiniteStack' : cannot be caught as the destructor and/or copy constructor are inaccessible
1>c:\users\ryan\documents\visual studio 11\projects\programming ii\prog07-part1\prog07-part1\main.cpp(54): error C2065: 'StackFullException' : undeclared identifier
1>c:\users\ryan\documents\visual studio 11\projects\programming ii\prog07-part1\prog07-part1\main.cpp(54): error C2316: 'FiniteStack' : cannot be caught as the destructor and/or copy constructor are inaccessible
1>c:\users\ryan\documents\visual studio 11\projects\programming ii\prog07-part1\prog07-part1\main.cpp(54): error C2312: 'FiniteStack' : is caught by 'FiniteStack' on line 52
1>c:\users\ryan\documents\visual studio 11\projects\programming ii\prog07-part1\prog07-part1\main.cpp(63): error C2065: 'C' : undeclared identifier
1>c:\users\ryan\documents\visual studio 11\projects\programming ii\prog07-part1\prog07-part1\main.cpp(63): error C2955: 'FiniteStack' : use of class template requires template argument list
1> c:\users\ryan\documents\visual studio 11\projects\programming ii\prog07-part1\prog07-part1\finitestack.h(6) : see declaration of 'FiniteStack'
1>c:\users\ryan\documents\visual studio 11\projects\programming ii\prog07-part1\prog07-part1\main.cpp(63): error C2316: 'FiniteStack<C>::StackEmptyException' : cannot be caught as the destructor and/or copy constructor are inaccessible
1>c:\users\ryan\documents\visual studio 11\projects\programming ii\prog07-part1\prog07-part1\main.cpp(65): error C2065: 'C' : undeclared identifier
1>c:\users\ryan\documents\visual studio 11\projects\programming ii\prog07-part1\prog07-part1\main.cpp(65): error C2955: 'FiniteStack' : use of class template requires template argument list
1>c:\users\ryan\documents\visual studio 11\projects\programming ii\prog07-part1\prog07-part1\main.cpp(65): error C2316: 'FiniteStack<C>::StackFullException' : cannot be caught as the destructor and/or copy constructor are inaccessible
1> FiniteStack.cpp
As it is a template type you need to specify the template as well if you want to access the exception classes. You could possibly create a "base" stack class which FiniteStack inherits which would define the exception classes instead.
Not sure why i had the virtual in there but I got rid of that. Also I found out that I was suppose to have the function declarations in the h file instead of the cpp. I was able to get everything to work, and I am very grateful for everyone's help, don't worry i'll have another program soon that I cannot figure out :)
Heres what I got to work for anyone who wants to know: