go to start Sol W14
|home |print view |recent changes |changed January 11, 2017 |
exact
|You are 54.81.139.56 <- set your identity!

#include <iostream>
struct Base {
  virtual void function() const{std::cout << "1";}
};

struct Derived : Base {
  void function() const {std::cout << "2";}
};

void call_function(Base &b) {
  b.function();
}

int main() {
  Derived d{};
  call_function(d);
  Base b{};
  call_function(b);
}

outputs 21

try with http://melpon.org/wandbox


|home |print view |recent changes |changed January 11, 2017 |
exact
|You are 54.81.139.56 <- set your identity!

Sol W14
go to start