help-gplusplus
[Top][All Lists]
Advanced

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

Re: Virtual inheritance and method overloading


From: Larry I Smith
Subject: Re: Virtual inheritance and method overloading
Date: Sun, 16 Jan 2005 17:40:31 GMT
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20041220

Michiel Nauta wrote:
L.S.

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 {
public:
  virtual ~Base1() {}
  virtual Base1& SomeFunc() =0;
};

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

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

The above should be:

    Base1& SomeFunc() {return *this;}

This matches the definition of SomeFunc() found in Base1.

Regards,
Larry

--
Anti-spam address, change each 'X' to '.' to reply directly.

reply via email to

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