【发布时间】:2013-09-24 16:49:53
【问题描述】:
我有这个类模板
template <typename T>
class Wrapper
{
public:
virtual void parse(std::string s) = 0;
protected:
T value;
};
理想情况下,每种类型都应该知道如何从字符串中解析自己,因此我希望拥有诸如
之类的专业化template<>
class Wrapper<int>
{
public:
virtual void parse(std::string s)
{
value = atoi(s.c_str());
}
};
但是,显然,我无法从主模板访问“值”成员。我得到的是这样的:
In member function 'virtual void Wrapper<int>::parse(std::string)':
error: 'value' is not a member of 'Wrapper<int>'
在value 前面添加this-> 没有帮助。
您知道如何解决这个问题吗?
谢谢
【问题讨论】:
标签: c++ templates inheritance template-specialization member-functions