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


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

Re: template with STL container

From Victor Bazarov <v.bazarov@comcast.invalid>
Newsgroups comp.lang.c++
Subject Re: template with STL container
Date 2011-10-04 10:01 -0400
Organization A noiseless patient Spider
Message-ID <j6f3kh$hd0$1@dont-email.me> (permalink)
References <j6f3eg$e4r$1@tdi.cu.mi.it>

Show all headers | View raw


On 10/4/2011 10:00 AM, softwareEngineer wrote:
> I'd like to manage a template in a STL vector container i.e. :
>
> template <typename T>
> class MY_Value
> {
> // ...
> T GetValue ();
>
> private :
> T _val;
> };
>
> now in my main would :
> std::vector <MY_Value*> v;

In order for this to compile, 'v' has to have a concrete type. 
Otherwise, how should the compiler know how much memory to allocate for 
it and how to initialize it?

> MyValue<int> iV1 = 1;
> MyValue<int> iV2 = 2;
> v[0] = &iV1;
> v[1] = &iV2;
>
> but i have had a problem because (obviously) MyValue it's a template .... ;
>
> There is a workaround to manage a template in a standard container
> (vector for example) ?

Well, is there a reason that

     std::vector<MY_Value<int>*> v;

does not work for you?

V
-- 
I do not respond to top-posted replies, please don't ask

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


Thread

template with STL container softwareEngineer <ovNOSPAM@NOSPAMlibero.it> - 2011-10-04 16:00 +0200
  Re: template with STL container Victor Bazarov <v.bazarov@comcast.invalid> - 2011-10-04 10:01 -0400
    Re: template with STL container softwareEngineer <ovNOSPAM@NOSPAMlibero.it> - 2011-10-04 16:16 +0200
      Re: template with STL container Victor Bazarov <v.bazarov@comcast.invalid> - 2011-10-04 10:44 -0400
      Re: template with STL container Noah Roberts <roberts.noah@gmail.com> - 2011-10-04 07:48 -0700
      Re: template with STL container Juha Nieminen <nospam@thanks.invalid> - 2011-10-04 19:14 +0000
      Re: template with STL container Nobody <nobody@nowhere.com> - 2011-10-05 09:51 +0100
        Re: template with STL container Victor Bazarov <v.bazarov@comcast.invalid> - 2011-10-05 08:05 -0400
          Re: template with STL container Juha Nieminen <nospam@thanks.invalid> - 2011-10-05 15:17 +0000
        Re: template with STL container Gert-Jan de Vos <gert-jan.de.vos@onsneteindhoven.nl> - 2011-10-05 05:43 -0700
        Re: template with STL container "Paul" <pchrist<nospam>or@yahoo.co.uk> - 2011-10-05 20:08 +0100
          Re: template with STL container softwareEngineer <ovNOSPAM@NOSPAMlibero.it> - 2011-10-07 10:42 +0200

csiph-web