Вопрос

Suppose i have this function:

class A {
    template<class Collider> void Init();
};

Can i specialize it for Sphere and Box?

I call this function from other template function, so it is not easy to just use InitForSphere and InitForBox.

Это было полезно?

Решение

Yes, you can.

template<>
void A::Init<Box>() {}

template<>
void A::Init<Sphere>() {}

call it like

A a;
a.Init<Box>();
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top