【发布时间】:2010-12-20 10:39:37
【问题描述】:
我确定这是可能的,但我就是做不到,即:如何在非模板类中定义函数模板?我尝试过这样的事情:
class Stack_T
{
private:
void* _my_area;
static const int _num_of_objects = 10;
public:
// Allocates space for objects added to stack
explicit Stack_T(size_t);
virtual ~Stack_T(void);
// Puts object onto stack
template<class T>
void put(const T&);
// Gets last added object to the stack
template<class T>
T& get()const;
// Removes last added object from the stack
template<class T>
void remove(const T&);
};
template<class T> //SOMETHING WRONG WITH THIS DEFINITION
void Stack_T::put<T>(const T& obj)
{
}
但它不起作用。我收到了这个错误消息:
'错误 1 错误 C2768:'Stack_T::put':非法使用显式模板参数'
谢谢
【问题讨论】: