开发者

Linker/Inheritance/Virtual function problems

开发者 https://www.devze.com 2023-02-18 11:38 出处:网络
Having trouble inheriting from a template class. Looks something like this: template<typename type>

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????


Don't you need to do something like this?

template<typename type>  
class base {  
protect:  
  ...  
public  
  ...  
  // provide implementation to be overriden
  virtual bool func1(type var1) { return (bool) 0; } 
};  

Because class derived : public base<type_spec_1> says derived is derved from a type base<type_spec_1>, but the type definition of base<type_spec_1> is not completely implemented yet?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号