As the title suggest I am trying to use a separate template class inside of a new template class. I am confused on the syntax. Also I am going to be using the functions inside of my List_3358 class and Im not sure how to go about implementing that. Any help would be greatly appreciated! Also im not sure how to format into code here on the forum.
// File name: stack_3358.h
//
// a Stack ADT
//
// This implementation uses a List_3358
// This implementation is a template
//***********************************************************
// Stack_3358: copy constructor
// Preconditions: None.
// Postconditions: New stack is created, which is a deep copy of src stack.
Stack_3358(const Stack_3358 & src);
//****************************
// makeEmpty: Removes all the items from the stack.
// Preconditions: None.
// Postconditions: All the items have been removed
void makeEmpty();
//****************************
// isEmpty: Checks to see if there are any items on the stack.
// Preconditions: None.
// Postconditions: Returns true if there are no items on the stack,
// else false.
bool isEmpty() const;
//****************************
// isFull: Determines if you have any more room to add items to the stack.
// Preconditions: None.
// Postconditions: Returns true if there is no more room to add items,
// else false.
bool isFull() const;
//****************************
// push: Adds newItem to the top of the stack.
// Preconditions: Stack is not full.
// Postconditions: newItem is at the top of the stack.
void push(const ItemType &);
//****************************
// pop: Removes topItem from stack and returns it.
// Preconditions: Stack is not empty.
// Postconditions: Top element has been removed from stack and a copy of the
// removed element is returned.
ItemType pop();
private:
//Template class should go here.
};
******Below is the template class I'm trying to declare inside my other class.
Note: you have to explicitly tell the compiler what type it should be anyway.
Since your Stack class only takes 1 Template argument, the case might be, that the nested class doesn't need to be a template class at all and just has the Same type as given in the Stack.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
template <typename T1>
class Stack_3358
{
public:
private:
class List_3358
{
public:
T1 data;
};
List_3358 item;
};