summaryrefslogtreecommitdiff
path: root/c,cc/slicing.cc
diff options
context:
space:
mode:
Diffstat (limited to 'c,cc/slicing.cc')
-rw-r--r--c,cc/slicing.cc43
1 files changed, 43 insertions, 0 deletions
diff --git a/c,cc/slicing.cc b/c,cc/slicing.cc
new file mode 100644
index 0000000..c89d99d
--- /dev/null
+++ b/c,cc/slicing.cc
@@ -0,0 +1,43 @@
+#include <iostream>
+#include <string>
+#include <vector>
+
+using namespace std;
+
+struct A {
+ public:
+ virtual string s() { return "a"; }
+};
+
+class B : public A {
+ public:
+ string s() { return "b"; }
+};
+
+B
+make_b()
+{
+ B b;
+ return b;
+}
+
+A
+make_a()
+{
+ return make_b();
+}
+
+int
+main(void)
+{
+ vector<A> x;
+ B b = make_b();
+ x.push_back(b);
+ cout << x[0].s() << endl;
+ B c;
+ x.push_back(c);
+ cout << x[1].s() << endl;
+
+ return 0;
+}
+