C++
virt.cxx
Go to the documentation of this file.
1 #include <iostream>
2 
3 class base {
4 
5 public:
6  base() {}
7 
8  virtual void id() { std::cout << "hi i am base\n"; }
9 };
10 
11 class derived : public base {
12 
13 public:
14  derived() { id(); }
15 
16  void id() override { std::cout << "hi i am derived\n"; }
17 };
18 
19 int main() {
20  std::cout << "base:\n";
21  base b;
22 
23  std::cout << "\nderived:\n";
24  derived d;
25 }
Definition: virt.cxx:3
virtual void id()
Definition: virt.cxx:8
base()
Definition: virt.cxx:6
Definition: virt.cxx:11
void id() override
Definition: virt.cxx:16
derived()
Definition: virt.cxx:14
int main()
Definition: virt.cxx:19