fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. class ADDON {
  5. std::string s;
  6.  
  7. public:
  8. ADDON() {
  9. s = "";
  10. }
  11.  
  12. ADDON(std::string in) {
  13. s = in;
  14. }
  15.  
  16. ADDON(const char in[]) {
  17. s = in;
  18. }
  19.  
  20. void operator=(const std::string in) {
  21. s = in;
  22. }
  23.  
  24. std::string getString() {
  25. return s;
  26. }
  27. };
  28.  
  29. template<typename T>
  30. void print_to_default_file(T &obj, ADDON addon = "")
  31. { std::cout << "first overload\n"; }
  32.  
  33. template<typename T>
  34. void print_to_default_file(T &obj, std::string objS) // or char* objS
  35. { std::cout << "second overload\n"; }
  36.  
  37. int main()
  38. {
  39. print_to_default_file("test","where will I go");
  40. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:39:52: error: call of overloaded ‘print_to_default_file(const char [5], const char [16])’ is ambiguous
prog.cpp:39:52: note: candidates are:
prog.cpp:30:6: note: void print_to_default_file(T&, ADDON) [with T = const char [5]]
prog.cpp:34:6: note: void print_to_default_file(T&, std::string) [with T = const char [5]; std::string = std::basic_string<char>]
stdout
Standard output is empty