Click on multiple2.cpp to get source.
#include <iostream>
#include <strings.h>
#include <cstring>
using namespace std;
class W {
protected: virtual char* f() {char *s = new char[7];
strcpy(s, "W::f()"); return s;}
public: virtual char* g() {char *s = new char[7];
strcpy(s, "W::g()"); return s;}
W() : m(5) {}
int m;
virtual ~W() {} // virtual functions create Warning
}; // end class W
class A : public virtual W {
public: char* f() {char *s = new char[7];
strcpy(s, "A::f()"); return s;}
virtual ~A() {}
}; // end class A
class B : public A {
public: char* g() {char *s = new char[7];
strcpy(s, "B::g()"); return s;}
B() : m(6) {}
int m;
virtual ~B() {}
}; // end class B
class C: public B, public virtual W {
private: char* f(){char *s = new char[7];
strcpy(s, "C::f()"); return s;}
public: char* h(){/* definition of C::h() */
char *s = new char[7];
cout << "in C::h, this->f(): " << this->f() << endl;
cout << "in C::h, this->g(): " << this->g() << endl;
if (0) this->C::h();
cout << "in C::h, this->B::g(): " << this->B::g() << endl;
cout << "in C::h, this->A::f(): " << this->A::f() << endl;
cout << "in C::h, this->W::f(): " << this->W::f() << endl;
cout << "in C::h, this->W::g(): " << this->W::g() << endl;
strcpy(s, "C::h()"); return s;
} // end C::h
virtual ~C() {}
}; // end class C
int main(void){
W* wp; A a; B b; C c;
/* body of main program */
cout << "C c; calling c.g(): " << c.g() << endl;
cout << "C c; calling c.W::g(): " << c.W::g() << endl;
cout << "C c; calling c.h(): " << endl; c.h(); // << c.h() << endl;
// Note: cout << "C c; calling c.h(): " << c.h() << endl;
// may execute the << in c.h() before the first << in the expression
// [Stroustrup 6.2.2, p. 122: order of subexpression evaluation
// is undefined].
cout << endl;
wp = (W*)&a; cout << "W* wp = &a, wp->g(): " << wp->g() << endl;
wp = (W*)&b; cout << "W* wp = &b, wp->g(): " << wp->g() << endl;
A* ap = (A*)&c; cout << "A* ap = &c, ap->f(): " << ap->f() << endl;
A a2(c); cout << "A a2(c), a2.g(): " << a2.g() << endl;
cout << c.m << " " << c.W::m << endl;
}