Hi,
Does anyone have any idea why I can't compile the following code snippet
in VC++ 7.1? It seems to work fine in Comeau C++.

struct Reader
{
virtual Reader* Clone() const = 0;
};

struct Writer
{
virtual Writer* Clone() const = 0;
};

struct X : public Reader, public Writer
{
X* Clone() const { return new X(*this); }
};

The error reported is
error C2511: 'Writer *X::Clone(void)' : overloaded member function not
found in 'X'
test6.cpp(55) : see declaration of 'X'

Re: Covariant Return Types and Multiple Inheritence by Doug

Doug
Tue May 11 14:48:04 CDT 2004

Jeff Paciga wrote:

>Hi,
>Does anyone have any idea why I can't compile the following code snippet
>in VC++ 7.1? It seems to work fine in Comeau C++.
>
>struct Reader
>{
> virtual Reader* Clone() const = 0;
>};
>
>struct Writer
>{
> virtual Writer* Clone() const = 0;
>};
>
>struct X : public Reader, public Writer
>{
> X* Clone() const { return new X(*this); }
>};
>
>The error reported is
>error C2511: 'Writer *X::Clone(void)' : overloaded member function not
>found in 'X'
> test6.cpp(55) : see declaration of 'X'

The docs say it isn't supported for virtual inheritance:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/vclrf103paragraph5covariantreturntypes.asp

But you're using simple MI. I've seen other posts which lead me to believe
VC supports the feature only for the leftmost base class. Maybe someone who
has the Whidbey alpha handy can test it for you there.

--
Doug Harrison
Microsoft MVP - Visual C++

Re: Covariant Return Types and Multiple Inheritence by jeffp

jeffp
Thu May 13 08:21:54 CDT 2004

"Doug Harrison [MVP]" <dsh@mvps.org> wrote in message news:<aab2a09g15731vn1qepst3j5g9158k1n36@4ax.com>...
> But you're using simple MI. I've seen other posts which lead me to believe
> VC supports the feature only for the leftmost base class.

That is consistent with what I am seeing... but just to follow up, the
example I posted compiles if I make Reader::Clone and Writer::Clone
non-pure virtual, and non-const. They have to be either pure virtual or
const for the example to fail. Weird.