我确定它是可能的,但我不能做到这一点,即:如何在非模板类中定义函数模板?我尝试过这样的事情:非模板类中的函数模板
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 ::把’:非法使用显式模板参数”
谢谢
我tryied这一点,但我得到一个错误: “错误错误LNK2019:无法解析的外部符号 “市民:无效__thiscall Stack_T ::把(INT常量和)”(?? $放3 H @ Stack_T @@ QAEXABH @ Z)在函数_wmain中引用\t Stack_of_Objects.obj ' –
2009-11-25 19:56:24