Afficher un message
Vieux 01/07/2008, 04h30   #2
Barry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: template specialization for pointer-to-type

On 7ÔÂ1ÈÕ, ÉÏÎç2ʱ59·Ö, ".rhavin grobert" <cl...@yahoo.de> wrote:
> guess you have the following:
>
> _________________________________________________
> template <class T>
> class CQVector
> {
> public:
> // find an element, returns index or -1 if none is found
> int find(int id) const;
> private:
> std::vector<T> m_vec;
>
> };
>
> template <class T>
> int CQVector<T>::find(int id) const
> {
> int iCnt = m_vec.size();
> while (iCnt-->0)
> {
> if (m_vec[iCnt].ID() == id)
> break;
> }
> return iCnt;}
>
> _________________________________________________
>
> this finds an element in the vector by calling elements fn ID() and
> compiles for all structures/classes that have an ID() memeber-fn
> returning something comparable to int.
>
> now i also want the possibility to store pointers, eg
>
> CQVector<MyClass*> m_foo;
>
> and need some specialisation that does a...
> _________________________________________________
>
> int iCnt = m_vec.size();
> while (iCnt-->0)
> {
> if (m_vec[iCnt]->ID() == id)
> break;
> }
> return iCnt;
> _________________________________________________
>
> what syntax is need ed for the specialisation?
> something like template<class*T> doesnt work...
>



template <class T>
class CQVector<T*>
{
...
};
  Réponse avec citation
 
Page generated in 0,05139 seconds with 9 queries