fork download
  1. struct T
  2. {
  3. int a;
  4. };
  5.  
  6. struct C
  7. {
  8. T& r;
  9. C(T& v) : r(v) {}
  10. };
  11.  
  12. struct E : T
  13. {
  14. T& r;
  15. E(T const& v) : r(*this), T(v) {} // ok
  16. };
  17.  
  18. struct F : C, T // base order doesn't matter here
  19. {
  20. F(T const& v) : C(*this), T(v) {} // error : C::r is not initialized properly
  21. //F(T const& v) : C(*static_cast<T*>(this)), T(v) {} // ok
  22. //F(T const& v) : C(static_cast<T&>(*this)), T(v) {} // ok
  23. };
  24.  
  25. int main()
  26. {
  27. T v;
  28. F f(v);
  29. f.r.a = 1;
  30. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In constructor 'F::F(const T&)':
prog.cpp:20:34: error: call of overloaded 'C(F&)' is ambiguous
prog.cpp:9:5: note: candidates are: C::C(T&)
prog.cpp:7:1: note:                 C::C(const C&)
stdout
Standard output is empty