Re: Accesso a parametro non tipo di classe template base
Von: Nicola Musatti (nicola.musatti@gmail.com) [Profil]
Datum: 12.08.2008 09:45
Message-ID: <2ea723d0-035a-43c9-9685-560819899654@k7g2000hsd.googlegroups.com>
Newsgroup: it.comp.lang.c++
Datum: 12.08.2008 09:45
Message-ID: <2ea723d0-035a-43c9-9685-560819899654@k7g2000hsd.googlegroups.com>
Newsgroup: it.comp.lang.c++
On Aug 11, 7:34 pm, Andrea Venturoli <ml.diespam...@netfence.it> wrote: > Ciao. > Probabilmente sto sbagliando approccio, pero' provo a porvi il quesito > lo stesso. > > Si abbia qualcosa del genere: > > template <int numero,typename tipo> struct A { > tipo data[numero]; > typedef tipo value_type; > > }; > > template <typename tipo> struct B:public A<3,tipo> { > ... > > }; > > template <class V> class C { > V v; //Dove si suppone che V sia B<qualcosa> > > }; > > Come faccio in C a sapere quanto vale "numero" di V (nel mio esempio 3)? > Posso usare typename V::value_type per sapere cos'e' "tipo", ma non so > come agire nel caso di parametri non tipo. Devi assegnarlo ad un membro dato costante statico pubblico, tipo: > template <int numero,typename tipo> struct A { > tipo data[numero]; > typedef tipo value_type; static const int num = numero; > }; Tipicamente num non occupa spazio in memoria, a meno che tu non ne utilizzi l'indirizzo. Ciao, Nicola[ Auf dieses Posting antworten ]
Antworten
- Andrea Venturoli (12.08.2008 10:57)
