What will be the result of different calls of class and structure methods?
#include <iostream>

class A {
public:
  virtual A &Get() {
    std::cout << "A";
    return *this;
  }
};

struct B : A {
  B &Get() {
    std::cout << "B";
    return *this;
  }
};


int main(int, char *argv[]) {
  B b;
  A &a1(b), a2(a1), *a3(&a2), *a4(&a1);
  b.Get();
  a1.Get();
  a2.Get();
  a3->Get();
  a4->Get();
}

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes