Witam
Od C++11 można użyć tag dispatching jak niżej. A co było przed C++11? Dało się wyspecjalizować jakoś jedną metodę w klasie bez definicji nowej klasy?
#include <stdio.h>
#include <iostream>
#include <type_traits>
using namespace std;
template<class T, int N>
class Klasa
{
public:
Klasa(const T& t):mT(t){}
T metoda(const T& t);
protected:
T mT;
};
template<class T, int N>
T Klasa<T, N>::metoda(const T& t)
{
if(is_floating_point<T>::value)
cout << "float T specialization: " << t << endl;
else
cout << t << endl;
return mT;
}
int main()
{
cout << Klasa<unsigned, 7>(8).metoda(5) << endl;
cout << Klasa<float, 7>(8).metoda(5) << endl;
return 0;
}