c++ - Throw exception if the datatype of argument which passed to a function is string type -


i have method can receive datatype of template class type. in function, have further processing if datatype of arguments not of string type. and, if arguments of string type then, want exception handling.

template<class k>  class student { private:     k array[10]; public:     void assignvalues( k const& index,  const k& val )     {          //now, want check here index not of string type          array[index] = val;     }  };  int main() {     student <int> object;     object.assignvalues(5,9);      //but not work     student <string> object;     object.assignvalues("hi","value");      return 0; } 

what using std::is_same:

if (std::is_same<k, string>::value) {     // k string ... } 

Comments