diff options
author | Patrick Simianer <p@simianer.de> | 2014-09-06 22:32:49 +0100 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2014-09-06 22:32:49 +0100 |
commit | 626c2cd921e7442c20ac1be7be0b9ecb44d00c95 (patch) | |
tree | d9bb1d4c670ffc3e6094202dc2d5764040c4c1ff /c,cc/derived.cc | |
parent | 01215a3f542df6692ef12b4e4b5fed551d065545 (diff) |
cc examples
Diffstat (limited to 'c,cc/derived.cc')
-rw-r--r-- | c,cc/derived.cc | 28 |
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; +} + |