fork download
  1. #include <iostream>
  2.  
  3. template <std::size_t SIZE> class A
  4. {
  5. char b[SIZE];
  6.  
  7. public:
  8. using const_buffer_t = const char (&)[SIZE];
  9. using my_type = A<SIZE>;
  10.  
  11. A() : b{} { std::cout << "size: " << SIZE << " ctor 1\n"; }
  12. A(const_buffer_t) : b{} { std::cout << "size: " << SIZE << " ctor 2\n"; }
  13. template <typename=void>
  14. A(const char * const) : b{} { std::cout << "size: " << SIZE << " ctor 3\n"; }
  15. explicit A(const my_type &) : b{} { std::cout << "size: " << SIZE << " ctor 4\n"; }
  16.  
  17. template <std::size_t OTHER_SIZE>
  18. A(const char (&)[OTHER_SIZE]) : b{} { std::cout << "size: " << SIZE << " ctor 5\n"; }
  19.  
  20. template <std::size_t OTHER_SIZE>
  21. explicit A(const A<OTHER_SIZE> &) : b{} { std::cout << "size: " << SIZE << " ctor 6\n"; }
  22. };
  23.  
  24. int main()
  25. {
  26. //A<5> a("five");
  27. A<5> b("0123456789");
  28. //A<9> c(a);
  29. A<5> d;
  30. A<5> e(d);
  31. A<9> f(d);
  32.  
  33. return 0;
  34. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:27:21: error: call of overloaded ‘A(const char [11])’ is ambiguous
  A<5> b("0123456789");
                     ^
prog.cpp:27:21: note: candidates are:
prog.cpp:18:2: note: A<SIZE>::A(const char (&)[OTHER_SIZE]) [with unsigned int OTHER_SIZE = 11u; unsigned int SIZE = 5u]
  A(const char (&)[OTHER_SIZE]) : b{} { std::cout << "size: " << SIZE << " ctor 5\n"; }
  ^
prog.cpp:15:11: note: A<SIZE>::A(const my_type&) [with unsigned int SIZE = 5u; A<SIZE>::my_type = A<5u>]
  explicit A(const my_type &) : b{} { std::cout << "size: " << SIZE << " ctor 4\n"; }
           ^
prog.cpp:14:2: note: A<SIZE>::A(const char*) [with <template-parameter-2-1> = void; unsigned int SIZE = 5u]
  A(const char * const)  : b{} { std::cout << "size: " << SIZE << " ctor 3\n"; }
  ^
stdout
Standard output is empty