cosa succede se ho una classe generica con tipo T e ho una funzione che ritorna con T. e voglio che la mia funzione restituisca una stringa specifica se il typid (T) = = typedef (string)?
template<class T> class Class1 { public: Class1(); ~Class1(); T func(); }; template <class T> T Class1<T>::func() { string d = "T = string"; if (typeid(string) == typeid(T)) return (T)d; <-- here I got the problem }
En title : return a generic function with specified type
ecco un esempio di esplicita specializzazione di una funzione membro di un modello di classe: