假设我有这个功能:
class A {
template<class Collider> void Init();
};
我可以将它专门用于 Sphere 和 Box 吗?
我是从其他模板函数中调用这个函数的,所以只使用 InitForSphere 和 InitForBox 并不容易。
最佳答案
是的,你可以。
template<>
void A::Init<Box>() {}
template<>
void A::Init<Sphere>() {}
这样称呼
A a;
a.Init<Box>();
关于c++ - 特化返回 void 且没有参数的成员函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20760074/