summaryrefslogtreecommitdiff
path: root/tests/exec/multisuper3.cpp
diff options
context:
space:
mode:
authorAlex AUVOLAT <alex.auvolat@ens.fr>2014-01-08 22:51:33 +0100
committerAlex AUVOLAT <alex.auvolat@ens.fr>2014-01-08 22:51:33 +0100
commit622f76becf4b8cbf4a56daa913070487481b87cf (patch)
tree69396cd00e9b198a5323138cf6c8d8ab75afbd1b /tests/exec/multisuper3.cpp
parentac9d321fe8cb789d4f3fda6e07ac96d6d3fa73b1 (diff)
downloadLPC-Projet-622f76becf4b8cbf4a56daa913070487481b87cf.tar.gz
LPC-Projet-622f76becf4b8cbf4a56daa913070487481b87cf.zip
Added tests for multiple inheritance.
Diffstat (limited to 'tests/exec/multisuper3.cpp')
-rw-r--r--tests/exec/multisuper3.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/exec/multisuper3.cpp b/tests/exec/multisuper3.cpp
new file mode 100644
index 0000000..55f4c45
--- /dev/null
+++ b/tests/exec/multisuper3.cpp
@@ -0,0 +1,76 @@
+#include <iostream>
+
+class A {
+ public:
+ int y;
+ A();
+ virtual int f(int x);
+};
+
+class B {
+ public:
+ int z;
+ B();
+ int g(int x);
+};
+
+class C : public A, public B {
+ public:
+ int q;
+ C();
+ virtual int f(int x);
+ int g(int x);
+};
+
+A::A() {
+ y = 12;
+}
+
+B::B() {
+ z = 7;
+}
+
+C::C() {
+ q = 11;
+}
+
+int A::f(int xopia) {
+ y++;
+ return xopia * y;
+}
+
+int B::g(int xulliver) {
+ z++;
+ return xulliver * z;
+}
+
+int C::f(int xerod) {
+ return xerod * q;
+}
+
+int C::g(int xavon) {
+ return xavon * q * 404;
+}
+
+int main() {
+ A test2;
+ std::cout << "A.f(1) = " << test2.f(1) << "\n";
+
+ B test3;
+ std::cout << "B.g(1) = " << test3.g(1) << "\n";
+
+ C test;
+ std::cout << "C.f(1) = " << test.f(1) << "\n";
+ std::cout << "C.g(1) = " << test.g(1) << "\n";
+ A *q = &test;
+ std::cout << "(C as A).f(1) = " << q->f(1) << "\n";
+ std::cout << "C.f(1) = " << test.f(1) << "\n";
+ std::cout << "(C as A).f(1) = " << q->f(1) << "\n";
+ std::cout << "C.f(1) = " << test.f(1) << "\n";
+ B *r = &test;
+ std::cout << "(C as B).g(1) = " << r->g(1) << "\n";
+ std::cout << "C.g(1) = " << test.g(1) << "\n";
+ std::cout << "(C as B).g(1) = " << r->g(1) << "\n";
+ std::cout << "C.g(1) = " << test.g(1) << "\n";
+}
+