aboutsummaryrefslogtreecommitdiff
path: root/semestr-4/ask/lista7/zad7.cpp
blob: 073224f08934ed90863637b1ec0f50e869615d79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
struct Base {
  Base(int n) : data(n) {}
  int data;
  virtual int doit(int n) { return n - data; }
};
struct Derived : Base {
  Derived(int n) : Base(n + 1) {}
  int doit(int n) { return n * data; }
};

int doit(Base *bp) {
  return bp->doit(1);
}

int main(int argc, char *argv[]) {
  Base b = Base(10);
  Derived d = Derived(20);
  return doit(&b) + doit(&d);
}