|

楼主 |
发表于 2007-10-24 00:00:00
|
显示全部楼层
Re:求各位先知指点一下,为啥不能特化类模板的函数成员
struct Vec3{
public:
float x,y,z;
};
struct _TS_LOCAL{} TS_LOCAL;
struct _TS_PARENT{} TS_PARENT;
struct _TS_WORLD{} TS_WORLD;
class CNodeAccessary {};
template<typename TC, typename TS_TYPE>
class TTranslateImpl :public CNodeAccessary
{
public:
void operator()(TC *_this, TS_TYPE);
};
template <typename TC>
class CNode
{
public:
template<typename TS_TYPE>
void Translate(TS_TYPE trait) {
TTranslateImpl<TC,TS_TYPE>(this, trait);
}
protected:
Vec3 m_Pos;
};
template<typename TC>
class TTranslateImpl<TC, _TS_LOCAL>
{
public:
TTranslateImpl(CNode<TC> *_this, _TS_LOCAL) {
// -test
//this _this->m_Pos.x += 1.0f;
printf("_TS_LOCAL\n");
}
};
template<typename TC>
class TTranslateImpl<TC, _TS_PARENT>
{
public:
TTranslateImpl(CNode<TC> *_this, _TS_PARENT) {
printf("_TS_PARENT\n");
}
};
template<typename TC>
class TTranslateImpl<TC, _TS_WORLD>
{
public:
TTranslateImpl(CNode<TC> *_this, _TS_WORLD) {
printf("_TS_WORLD\n");
}
};
void main()
{
CNode<void> node;
node.Translate(TS_LOCAL);
node.Translate(TS_WORLD);
node.Translate(TS_PARENT);
}
恩,我这样写,可以编译了 |
|