fork download
  1. #include <iostream>
  2. struct Bar {
  3. int n;
  4. Bar(int v) : n(v) {
  5. std::cout << "Bar " << n << " constructed\n";
  6. }
  7. Bar& operator=(const Bar& other) {
  8. std::cout << "Bar " << n << " assigned from " << other.n << "\n";
  9. n = other.n;
  10. return *this;
  11. }
  12. };
  13. struct Foo
  14. {
  15. Bar a;
  16. Bar b;
  17.  
  18. Foo(Bar c, Bar d) : a(b = c), b(d) { }
  19. };
  20.  
  21. int main()
  22. {
  23. Foo f(Bar(1), Bar(2));
  24. }
  25.  
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:8: warning: ‘f.Foo::b.Bar::n’ is used uninitialized in this function
prog.cpp:23: note: ‘f.Foo::b.Bar::n’ was declared here
stdout
Bar 2 constructed
Bar 1 constructed
Bar 0 assigned from 1