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


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

Re: Simple inheritance-template question

From "crea" <no@invalid.com>
Newsgroups comp.lang.c++
References (1 earlier) <90nudcFeeiU16@mid.individual.net> <_Lzpp.51518$7u3.30656@newsfe04.ams2> <3ba65432-9aa1-4c9c-8326-59496b82f3e0@p3g2000vbv.googlegroups.com> <XKApp.8510$bI3.5478@newsfe15.ams2> <600280e3-4c70-4492-a876-a305db5e4799@n2g2000prj.googlegroups.com>
Subject Re: Simple inheritance-template question
Message-ID <dVBpp.546$IK1.368@newsfe10.ams2> (permalink)
Organization virginmedia.com
Date 2011-04-14 13:38 +0100

Show all headers | View raw


"Goran" <goran.pusic@gmail.com> wrote in message 
news:600280e3-4c70-4492-a876-a305db5e4799@n2g2000prj.googlegroups.com...
> but AA has like 5 different this kind of fucntions. Shall I just create a
> virtual function for all of them (5 of them)? I could obviously put them 
> to
> be private. But is there any easier way... this is doable, but needs to
> override many functions.

"(Not private, protected, you need to override).

Overrides seem^^^ to be trivial: create a different object type given
some parameters, so why not?

(^^^: I am guessing that after new Data() you actually put something
useful in that object)."

I just checked, and actually the only place where I need some kind of 
virtual calling is when I do this in couple of places:
m_Data.data.Add(new Data(...));

So  the new -operation needs some kind of virtual version. hmmm , maybe just 
to create a function NewObject:

in AA:

virtual Data NewObject()

{ return new Data(); }



and then have in BB:

virtual BBData NewObject()

{ return new BBData(); }



so the call in AA goes now:



m_Data.data.Add(NewObject());



What do you think!! Looks like perfect.

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Simple inheritance-template question "crea" <no@invalid.com> - 2011-04-14 10:26 +0100
  Re: Simple inheritance-template question Ian Collins <ian-news@hotmail.com> - 2011-04-14 21:51 +1200
    Re: Simple inheritance-template question "crea" <no@invalid.com> - 2011-04-14 11:12 +0100
      Re: Simple inheritance-template question "crea" <no@invalid.com> - 2011-04-14 11:29 +0100
      Re: Simple inheritance-template question Goran <goran.pusic@gmail.com> - 2011-04-14 03:56 -0700
        Re: Simple inheritance-template question "crea" <no@invalid.com> - 2011-04-14 12:19 +0100
          Re: Simple inheritance-template question Goran <goran.pusic@gmail.com> - 2011-04-14 04:58 -0700
            Re: Simple inheritance-template question "crea" <no@invalid.com> - 2011-04-14 13:25 +0100
            Re: Simple inheritance-template question "crea" <no@invalid.com> - 2011-04-14 13:38 +0100
              Re: Simple inheritance-template question "crea" <no@invalid.com> - 2011-04-14 13:48 +0100
                Re: Simple inheritance-template question Goran <goran.pusic@gmail.com> - 2011-04-14 06:06 -0700
    One template solution I know, but... "crea" <no@invalid.com> - 2011-04-14 11:41 +0100
      Re: One template solution I know, but... Victor Bazarov <v.bazarov@comcast.invalid> - 2011-04-14 09:32 -0400
        Re: One template solution I know, but... "crea" <no@invalid.com> - 2011-04-14 15:19 +0100
  Re: Simple inheritance-template question "crea" <no@invalid.com> - 2011-04-14 10:59 +0100
    Re: Simple inheritance-template question Noah Roberts <dont@email.me> - 2011-04-14 09:29 -0700
      Re: Simple inheritance-template question "crea" <no@invalid.com> - 2011-04-15 07:50 +0100
      Re: Simple inheritance-template question "crea" <no@invalid.com> - 2011-04-17 17:22 +0100

csiph-web