Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #17248

Re: Template overriding base class virtual function?

From Peter Davis <pfd@pfdstudio.com>
Newsgroups comp.lang.c++
Subject Re: Template overriding base class virtual function?
Date 2012-07-25 09:06 -0400
Organization PFD Studio
Message-ID <juor0e$hsd$1@newscl01ah.mathworks.com> (permalink)
References <jum7qg$cdl$1@newscl01ah.mathworks.com> <d1829331-71a5-4994-a135-2f2b04632ef2@googlegroups.com> <6ab40b6b-8de3-41e1-8289-71e27d41bee8@googlegroups.com>

Show all headers | View raw


On 7/24/2012 2:38 PM, Noah Roberts wrote:
> On Tuesday, July 24, 2012 7:23:35 AM UTC-7, Casey wrote:
>> On Tuesday, July 24, 2012 8:26:40 AM UTC-5, Peter Davis wrote:
>> &gt; If I make both Base and Cloneable be virtual base classes, this works,
>> &gt; but I don&amp;#39;t understand why this is necessary. Why doesn&amp;#39;t the template
>> &gt; just override the Base definition of clone()?
>>
>> Because &quot;the template&quot; (Cloneable&lt;Derived&gt;) doesn&#39;t derive from Base. Try:

Thank you. The actual code is more complex, as it is the implementation 
side of a pimpl pattern, but I'll see if I can adapt this.

>
> Additionally, you'll want to review what happens when you have the same function defined in two unrelated base classes but don't hide it:
>
> http://crazycpp.wordpress.com/2011/03/28/name-resolution-and-overloading/
>

Thanks. I think a big part of the problem is that I was not able to make 
the clone() method on Base be pure virtual. That's because there are 
other classes, also abstract, whose default constructors created new 
Base objects, so Base could not have any pure virtual methods.

Thank you both!
-pd

-- 
----
The Tech Curmudgeon
http://www.techcurmudgeon.com

Back to comp.lang.c++ | Previous | NextPrevious in thread | Find similar


Thread

Template overriding base class virtual function? Peter Davis <pfd@pfdstudio.com> - 2012-07-24 09:26 -0400
  Re: Template overriding base class virtual function? Casey <cartec69@gmail.com> - 2012-07-24 07:23 -0700
    Re: Template overriding base class virtual function? Noah Roberts <roberts.noah@gmail.com> - 2012-07-24 11:38 -0700
      Re: Template overriding base class virtual function? Peter Davis <pfd@pfdstudio.com> - 2012-07-25 09:06 -0400

csiph-web