Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #3649
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Ian Collins <ian-news@hotmail.com> |
| Newsgroups | comp.lang.c++ |
| Subject | Re: Simple inheritance-template question |
| Date | Thu, 14 Apr 2011 21:51:40 +1200 |
| Lines | 40 |
| Message-ID | <90nudcFeeiU16@mid.individual.net> (permalink) |
| References | <f5zpp.27551$rF.22899@newsfe12.ams2> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | individual.net U1H/LhxF8/RqiH7gImAuoQl8Z5oT0W1dTt655Y29fGGUMmGk7d |
| Cancel-Lock | sha1:edzqtzLqIBRD3reEjD/GDt5gtyw= |
| User-Agent | Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4 |
| In-Reply-To | <f5zpp.27551$rF.22899@newsfe12.ams2> |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.c++:3649 |
Show key headers only | View raw
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