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


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

One template solution I know, but...

From "crea" <no@invalid.com>
Newsgroups comp.lang.c++
References <f5zpp.27551$rF.22899@newsfe12.ams2> <90nudcFeeiU16@mid.individual.net>
Subject One template solution I know, but...
Message-ID <ebApp.12935$tp6.2103@newsfe25.ams2> (permalink)
Organization virginmedia.com
Date 2011-04-14 11:41 +0100

Show all headers | View raw


This would definitely work:
template <class T> class Data
{
public:
 T p;
};

template <class T> class AA
{
public:
Data<T> m_data;
};

template <class T> class BB : public AA
{
public:
};

So I could create object like this:

AA<int> b;
BB<string> b;

Ok, this definitely works, but its a bit difficult to put all of those 
templates in all classes. I was thinking that because the only thing I need 
here is that BB has different Data::p type than AA, so it could be done 
hidden in BB class somehow. So there is no need to tell it when calling:

BB<string> b;

but rather just:
BB b;

I dont think we need to tell the type when creating objects, because the 
classes already know what type it should be (if created an object from BB it 
ALWAYS has string type and AA ALWAYS has int type - thats the situation).

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