链接器/继承/虚拟函数问题
从模板类继承时遇到问题。
看起来像这样:
template<typename type>
class base {
protect:
...
public
...
virtual bool func1(type var1);
};
// 这个类不是模板化的,而是从模板类派生的,不知道它是否有问题
class derived : public base<type_spec_1> {
protected:
...
public:
...
bool func1(type_spec_1);// function I wish to override;
};
// 在 .cpp 中,我尝试确定函数的范围,它编译但不链接
bool derived::func1(type_spec_1 type){ return false; };
链接器给了我此格式的错误:LNK2001,无法解析的符号 base::func1(type_spec_1);
就像它没有看到 "driven"==base"
如果可能的话,我怎样才能为此提供正确的语法???
Having trouble inheriting from a template class.
Looks something like this:
template<typename type>
class base {
protect:
...
public
...
virtual bool func1(type var1);
};
// this class is not templated but derives from template class, don't know if its issue
class derived : public base<type_spec_1> {
protected:
...
public:
...
bool func1(type_spec_1);// function I wish to override;
};
// In the .cpp, I try to scope the function, it compiles but it does not link
bool derived::func1(type_spec_1 type){ return false; };
The linker gives me an error in this format: LNK2001, unresolved symbol base::func1(type_spec_1);
Like it does not see that "derived"==base"<type_type_1>"
How can I provide the proper syntax for this, if it is even possible????
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不需要做这样的事情吗?
因为
class generated : public base
表示衍生
是从类型base
派生的,但是的类型定义base
尚未完全实现?Don't you need to do something like this?
Because
class derived : public base<type_spec_1>
saysderived
is derved from a typebase<type_spec_1>
, but the type definition ofbase<type_spec_1>
is not completely implemented yet?