aboutsummaryrefslogtreecommitdiff
path: root/Semestr 4/ask/lista7/zad7.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Semestr 4/ask/lista7/zad7.cpp')
-rw-r--r--Semestr 4/ask/lista7/zad7.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/Semestr 4/ask/lista7/zad7.cpp b/Semestr 4/ask/lista7/zad7.cpp
new file mode 100644
index 0000000..073224f
--- /dev/null
+++ b/Semestr 4/ask/lista7/zad7.cpp
@@ -0,0 +1,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);
+} \ No newline at end of file