This is a Python and C++ question.
I am experimenting with multiple inhertiance and I came across this example.
B1 B2
\ /
D
Say I have two (independent?) parent classes B1, B2 and one child class D. We're only interested in objects of class D.
class B1:
def f1(self):
print "In f1"
class B2:
def f2(self):
self.f1()
class D (B1, B2):
def fD(self):
self.f2()
d = D()
d.fD()
Output: In f1
What's interesting (at least to me) is that class B2 has no knowledge about class B1 and yet f2 can call self.f1() with no problems.
I tried to replicate this exact thing in C++ and I couldn't make it work because I don't know how to call f1 from f2.
class B1 {
public:
virtual ~B1() {}
virtual void f1() { cout << "In f1" << endl; }
};
class B2 {
public:
virtual ~B2() {}
virtual void f2() { /* What goes here?? */ }
};
class D : public B1, public B2 {
public:
void fD() { f2(); }
};
So, I want to know how/why Python can handle this but C++ cannot?
Also, what minimal changes can we make to the C++ code to make it behave like the Python code?
TheType.method(self, ..)object)? If that's important then the answer should be edited.