fork(2) download
  1. #include <stdio.h>
  2. #include <initializer_list>
  3.  
  4. struct A{
  5. int x;
  6. A():x(0){}
  7. void operator=(std::initializer_list<int> a){printf("int[%lld]:",a.size());for (auto x:a) printf(" %d",x); printf("\n");}
  8. void operator=(float a){printf("float: %.1f\n",a);}
  9. };
  10.  
  11. struct B:A{
  12. template <typename T>
  13. void operator=(T x){
  14. A::operator=(x);
  15. }
  16. };
  17.  
  18.  
  19.  
  20. int main() {
  21.  
  22. A a;
  23. a={1,2,5};
  24. a=5.6;
  25.  
  26. B b;
  27. b={1,5,6};
  28. b=4.7;
  29.  
  30. }
  31.  
Compilation error #stdin compilation error #stdout 0s 4968KB
stdin
Standard input is empty
compilation info
prog.cpp:7:67: warning: format specifies type 'long long' but the argument has type 'std::initializer_list::size_type' (aka 'unsigned long') [-Wformat]
        void operator=(std::initializer_list<int> a){printf("int[%lld]:",a.size());for (auto x:a) printf(" %d",x); printf("\n");}
                                                                 ~~~~    ^~~~~~~~
                                                                 %zu
prog.cpp:27:3: error: no viable overloaded '='
        b={1,5,6};
        ~^~~~~~~~
prog.cpp:11:8: note: candidate function (the implicit copy assignment operator) not viable: cannot convert initializer list argument to 'const B'
struct B:A{
       ^
prog.cpp:11:8: note: candidate function (the implicit move assignment operator) not viable: cannot convert initializer list argument to 'B'
struct B:A{
       ^
prog.cpp:13:7: note: candidate template ignored: couldn't infer template argument 'T'
        void operator=(T x){
             ^
1 warning and 1 error generated.
stdout
Standard output is empty