Dear friends;
I write a stack template, the head file and the main are as follows; but when i test the push function, it give me the following error. i do not understand the reason. could you please help me out.
1>f:\computation\datastructure\stack template\stack template\main.cpp(31) : error C2664: 'Stack<T>::push' : cannot convert parameter 1 from 'double' to 'double &'
#include"StackTemplate.h"
#include<string>
int main()
{
Stack<double> c;
c.push(1.5);
}
#ifndef STACK_TEMPLATE
#define STACK_TEMPLATE
#include <iostream>
#include<stdexcept>
using namespace std;
template<typename T> class Stack
{
private:
class Node
{
public:
T* pItem; // Pointer to object T
Node* pNext; // Pointer to the next
// constructor a node from an object
Node(T& rItem):pItem(&rItem),pNext(0){}
Node():pItem(0),pNext(0){}
};
Node* pHead;
void copy(const Stack& aStack);
void freeMemory();
public:
Stack():pHead(0){} // default constructor for the stack
Stack(const Stack& aStack);
~Stack();
Stack& operator=(const Stack& aStack);
void push(T& rItem);
T& pop();
inline bool isEmpty(){return pHead==0;}
};
template<typename T> void Stack<T>::push(T& rItem)
{
Node* pNode=new Node(rItem);
pNode->pNext=pHead;
pHead=pNode;
}
#endif