summaryrefslogtreecommitdiff
path: root/c,cc/derived.cc
diff options
context:
space:
mode:
Diffstat (limited to 'c,cc/derived.cc')
-rw-r--r--c,cc/derived.cc28
1 files changed, 28 insertions, 0 deletions
diff --git a/c,cc/derived.cc b/c,cc/derived.cc
new file mode 100644
index 0000000..809378a
--- /dev/null
+++ b/c,cc/derived.cc
@@ -0,0 +1,28 @@
+#include <iostream>
+#include <vector>
+
+using namespace std;
+
+struct Base {
+ virtual int
+ index() { return -1; };
+};
+
+struct D1 : public Base {
+ int idx = 1;
+
+ virtual int
+ index() { return idx; }
+};
+
+int
+main(void)
+{
+ vector<Base*> v;
+ D1* d = new D1;
+ v.push_back(d);
+ cout << v.back()->index() << endl;
+
+ return 0;
+}
+