Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #3649
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Simple inheritance-template question |
| Date | 2011-04-14 21:51 +1200 |
| Message-ID | <90nudcFeeiU16@mid.individual.net> (permalink) |
| References | <f5zpp.27551$rF.22899@newsfe12.ams2> |
On 04/14/11 09:26 PM, crea wrote:
> I cannot find solution to this:
>
> Here is the structure:
>
> template<class T> class Data
> {
> public:
> T p;
> };
>
> class AA
> {
> public:
> // here I would like to have a data member: m_data
> };
>
> class BB : public AA
> {
> public:
> };
>
> If an object is create from AA then I want it to have member data object
> created like this:
> Data<int> m_data;
>
> But if an object is created from BB then I want:
>
> Data<string> m_data;
>
> How to create a member data variable according to what class the object is
> created from? Is this even possible?
No, not really. To do so would break the "is a" rule (a BB isn't an
AA). Maybe make Data a union rather than a template?
What problem are you trying to solve?
--
Ian Collins
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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