[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Virtual inheritance and method overloading

From: Michiel Nauta
Subject: Virtual inheritance and method overloading
Date: Sat, 15 Jan 2005 14:05:56 +0100
User-agent: Mozilla Thunderbird 1.0 (X11/20041206)


I am trying to learn how to program in C++. At the moment I work my way
trough B. Preiss his book on data structures. I run here into an
excersize which won't compile with g++. A dressed down version (in
reality both Base1 and Base2 inherit from the same class, so I have a
diamond in the inheritance diagram for example) is included below.

#include <iostream>
using namespace std;

class Base1 {
  virtual ~Base1() {}
  virtual Base1& SomeFunc() =0;

class Base2 {
  virtual ~Base2() {}
  virtual void DoSomething() {cout << "Hallo world\n";}

class Derived: virtual public Base1, virtual public Base2 {
  Derived& SomeFunc() {return *this;}

int main() {
  Derived deriv;
  return 0;

The error message that I get is (I just use g++ -c test.cpp with version
3.3.4 of gcc on slackware 10): "test.cpp:16: sorry, unimplemented:
adjusting pointers for covariant returns". Line 16 is the line declaring
the Derived class. The error goes away if I either use ordinary
inheritance instead of virtual in line 16, or if the return type of
SomeFunc in class Derived is Base1& instead of Derived&.
I don't understand what is wrong, can someone please explain.

My reason to post on this list is that the Borland compiler doesn't

Michiel Nauta

reply via email to

[Prev in Thread] Current Thread [Next in Thread]