Hello All,
I was trying to execute couple of examples to understand the partial
template specialization concept.
Here is one among those.
#include<iostream>
using namespace std;
template<class T> class my_vec
{
public:
my_vec(){std::cout<<"im class my_vec<class T> \n";}
};
template <class T>
class my_vec<T*>
{
public:
my_vec()
{
std::cout<<"Im in my_vec<T*> \n";
}
};
template <class T> T mini(int i, int j);
main()
{
my_vec<float*> p;
system("pause");
}
In the C++ Programming language (3rd edition) by Bjarne Stroustrup, in
section 13.5, author had shown an example like this:
"To define a specialization that is used for every V e c t o r of
pointers and only for V e c t o r s of pointers,
we need a partial specialization:"
t e m p l a t e <c l a s s T > c l a s s V e c t o r <T *> : p r i v a
t e V e c t o r <v o i d *> {
p u b l i c :
t y p e d e f V e c t o r <v o i d *>B a s e ;
V e c t o r () :B a s e () {}
e x p l i c i t V e c t o r (i n t i ) :B a s e (i ) {}
T *& e l e m (i n t i ) { r e t u r n s t a t i c _ c a s t <T *&>(B a
s e :: e l e m (i )); }
T *& o p e r a t o r [](i n t i ) { r e t u r n s t a t i c _ c a s t
<T *&>(B a s e :: o p e r a t o r [](i )); }
/ / ...
};
basically he is extending the Vector<void*> to Vector<T*>. Why is it
so? In my example given above, I didn't derive from anything else. But
I think I'm solving the purpose to define a specialization that is
used for every my_vec of pointers and ONLY for my_vec of pointers.
I couldn't understand the author's intention correctly. Can someone
please explain ?
Thanks,
Bharath
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|