我知道你不能虚拟一个虚拟功能,而且我理解它背后的概念。但我仍然需要一种方法来克服一些我得到的错误。我能够使我的东西工作,但它看起来不正确。有关虚拟功能模板化的问题
我有课称为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
}
};
在Vector.h
:
tenplate<typename T>
class Vector
{
//some functions
};
现在我想模板化的system.h
VectorToLocal
仅举Vector<T>
,但我不能这样做,因为它是一个虚拟功能。我想要一个解决方法。我知道我可以有VectorToLocal
作为参数,但我不想这样做,我需要Vector<float>
,Vector<double>
等。
'T'型是否有限制? – 2010-03-25 20:30:53
T可以浮动,双重,复杂或复杂 –
jan
2010-03-25 21:01:41