0

I wanna stringify object in a template class, and I wrote this:

template <typename K, typename V>
template <typename T>
auto HashTable<K, V>::Stringify(T key) -> std::string{
  if(std::is_same<T, std::string>::value){...}
  else if(std::is_same<T, Bar*>::value){...}
  else{...}
}

when compiling, it say: "

In instantiation of ‘std::string HashTable<K, V>::Stringify(T) [with T 
= Bar*; K = int; V = Bar*; std::string = 
std::__cxx11::basic_string<char>]’:  invalid operands of types ‘const 
char [8]’ and ‘Bar* const’ to binary ‘operator+’"

according to the error pointing to line number of first if-statement, it seems that the instantiation matches the first if-statement

why is that? Is there some error in my code and how should I correct it? or is there another approach to my goal? thanks!

Jason
  • 36,170
  • 5
  • 26
  • 60
Xin_Wang
  • 1
  • 1
  • You're looking for `constexpr if`. See dupe: [Difference between "if constexpr()" Vs "if()"](https://stackoverflow.com/questions/43434491/difference-between-if-constexpr-vs-if) – Jason Apr 10 '23 at 09:23

0 Answers0