fork(6) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Base {
  5. Base operator+ (Base a) const { cout <<"Base+Base\n"; }
  6. Base& operator= (Base a) const { cout<<"Base=Base\n"; }
  7. };
  8. struct Derived : public Base {
  9. Derived()=default;
  10. Derived(const Base& a) : Base(a) { cout<<"consturct B from A\n"; }
  11. };
  12.  
  13.  
  14. int main() {
  15. Base a,b,c;
  16. c=a+b; // Base+Base Base=Base
  17. cout <<endl;
  18. Derived e,f,g;
  19. g = e+f; // Base + Base Construct B from A Base=Base (In fact default Derived=Derived, which uses Base=Base for the Base subobject)
  20. return 0;
  21. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
Base+Base
Base=Base

Base+Base
consturct B from A
Base=Base