question regarding templatization of virtual function

Posted by jan on Stack Overflow See other posts from Stack Overflow or by jan
Published on 2010-03-25T20:25:33Z Indexed on 2010/03/25 20:43 UTC
Read the original article Hit count: 372

Filed under:
|

Hi,

I am new to this forum and sorry If I am repeating this question. I know that you cannot templatize the virtual function and I do understand the concept behind it. But I still need a way to get across some errors I am getting it. I am able to make my stuff work but it doesn't look to me.

Here's the deal,

I have class called System,

#include "Vector.h"
class System
{
    virtual void VectorToLocal(Vector<T>& global_dir,const Vector<T>* global_pos =  0)      const  = 0;  
};

class UnresolvedSystem : public System
{
    virtual void VectorToLocal(Vector<T>& global_dir,const Vector<T>* global_pos = 0) const
    {
      //do something 
    }  
};

In Vector.h

tenplate<typename T>
class Vector
{
  //some functions
};

See now I want to templatize VectorToLocal in system.h to take just Vector, but I cannot do it as it is a virtual function. I want a work around. I know I can have VectorToLocal take Vector, Vector etc as arguments. But I do not want to do it.

Any help would be really appreciated.
Thanks in advance, Jan

© Stack Overflow or respective owner

Related posts about c++

Related posts about templates