S
Senthilraja
I have the following program using templates. Someone please let me know
the syntax to be used for defining the member functions push, pop etc.
as non-inline functions.
#include <iostream>
using namespace std;
template<class T, int size = 50>
class Stack
{
private:
//enum {ssize = 20};
T stack[size];
int top;
public:
Stack () : top(0) {}
T& operator[] (int index)
{
return stack[index];
}
void push (T n)
{
stack[top++] = n;
}
T pop ()
{
return stack[--top];
}
};
int main()
{
Stack<int> intStack;
cout<<"Size of intStack = "<<sizeof intStack<<endl;
for (int i=0; i<20; i++)
{
intStack.push (i*2);
}
for (int i=0; i<20; i++)
{
cout<<"i = "<<intStack.pop()<<endl;
}
return 0;
}
TIA,
Senthilraja.
the syntax to be used for defining the member functions push, pop etc.
as non-inline functions.
#include <iostream>
using namespace std;
template<class T, int size = 50>
class Stack
{
private:
//enum {ssize = 20};
T stack[size];
int top;
public:
Stack () : top(0) {}
T& operator[] (int index)
{
return stack[index];
}
void push (T n)
{
stack[top++] = n;
}
T pop ()
{
return stack[--top];
}
};
int main()
{
Stack<int> intStack;
cout<<"Size of intStack = "<<sizeof intStack<<endl;
for (int i=0; i<20; i++)
{
intStack.push (i*2);
}
for (int i=0; i<20; i++)
{
cout<<"i = "<<intStack.pop()<<endl;
}
return 0;
}
TIA,
Senthilraja.