ok,got it mostly done just this last group of errors
In instantiation of `std::ostream& operator<<(std::ostream&, const Stack<t, StackSize>&) [with t = int, StackItem = int, int StackSize = 100]':
43 E:\373\S_Stack.cpp instantiated from here
43 E:\373\S_Stack.cpp explicit instantiation of `std::ostream& operator<<(std::ostream&, const Stack<t, StackSize>&) [with t = int, StackItem = int, int StackSize = 100]' but no definition available
43 E:\373\S_Stack.cpp In instantiation of `std::ostream& operator<<(std::ostream&, const Stack<t, StackSize>&) [with t = int, StackItem = int, int StackSize = 100]':
43 E:\373\S_Stack.cpp instantiated from here
43 E:\373\S_Stack.cpp explicit instantiation of `std::ostream& operator<<(std::ostream&, const Stack<t, StackSize>&) [with t = int, StackItem = int, int StackSize = 100]' but no definition available
43 E:\373\S_Stack.cpp instantiated from here
43 E:\373\S_Stack.cpp explicit instantiation of `std::ostream& operator<<(std::ostream&, const Stack<t, StackSize>&) [with t = int, StackItem = int, int StackSize = 100]' but no definition available
header:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#ifndef S_Stack_h_
#define S_Stack_h_
#include <iostream>
template<class StackItem,int StackSize>
class Stack
{
template <class t>
friend std::ostream& operator<<(std::ostream & , const Stack<t,StackSize> &);
private:
StackItem Items[StackSize];
int Top;
public:
Stack(){Top=0;}
void Push(StackItem);
void Pop(StackItem &);
StackItem TopItem();
bool IsEmpty(){return (Top==0);};
bool IsFull () {return (Top==StackSize);};
void clear();
~Stack();
};
#endif
|
implementation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#include "S_Stack.h"
#include<iostream>
template<class StackItem,int StackSize>
void Stack<StackItem,StackSize>::Push(StackItem x)
{
Items[Top]=x;
Top++;
}
template<class StackItem,int StackSize>
void Stack<StackItem,StackSize>::Pop(StackItem &x)
{
x=Items[Top-1];
Top--;
}
template<class StackItem,int StackSize>
StackItem Stack<StackItem,StackSize>::TopItem()
{
return (Items[Top-1]);
}
template <class StackItem,int StackSize>
void Stack<StackItem,StackSize>::clear()
{
Top=0;
}
template<class StackItem,int StackSize>
Stack<StackItem,StackSize>::~Stack()
{
delete []Items;
}
template <class t,int StackSize>
std::ostream& operator<< (std::ostream &output,const Stack<t,StackSize> &s)
{
for(int i=0; i< s.Top; i++)
output<<s.Items[i]<<"|";
return output;
}
template class Stack<int,100>;
template std::ostream& operator<< (std::ostream &output, Stack<int,100> const&s);
|
main:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include "S_Stack.h"
#include<iostream>
int main()
{
Stack<int,100>i;
int a;
int x;
i.Push(1);
std::cout<<i<<std::endl;
i.Push(2);
std::cout<<i<<std::endl;
i.Push(3);
std::cout<<i<<std::endl;
i.Push(4);
std::cout<<i<<std::endl;
i.Push(5);
std::cout<<i<<std::endl;
a=i.TopItem();
std::cout<<"The top item is "<<a<<std::endl;
i.Pop(x);
std::cout<<x<<std::endl;
if(i.IsEmpty())
{
std::cout<<"Stack is empty"<<std::endl;
}
else
{
std::cout<<"Stack is not empty"<<std::endl;
}
if(i.IsFull())
{
std::cout<<"Stack is full"<<std::endl;
}
else
{
std::cout<<"Stack is not full"<<std::endl;
}
i.clear();
std::cout<<i<<std::endl;
if(i.IsEmpty())
{
std::cout<<"Stack is empty"<<std::endl;
}
else
{
std::cout<<"Stack is not empty"<<std::endl;
}
system ("pause");
return 0;
}
|
any help is appreciated.