| Tom Widmer [VC++ MVP] 2005-08-11, 9:05 am |
| jean Davy wrote:
> I want to specialize the insert function for a set of specific class, here
> is the code
>
> typedef std::set< CMyObject* > CMyObjectList;
> template <>
> CMyObjectList::_Pairib
> CMyObjectList::_Mybase::insert( const CMyObjectList::value_type& _Val )
> {
> ... some specific processing
> return CMyObjectList::_Mybase::insert( _Val ); // how to call the "base
> class" function ?
> }
>
> But I can't call the generic code of the template, the only way I found is
> to copy the code :((
The code is wrong for a number of reasons:
1. You shouldn't use _Uppercase identifiers in your code - they are
reserved for the implementation.
2. _Pairib is an undocumented typedef that is non-standard, liable to
change between versions, and banned from use in your code by the 1.
Instead, you'd write std::pair<CMyObjectList::iterator, bool>.
3. You must specialize std functions in the std namespace.
4. You are trying to specialize the _Mybase rather than the straight
CMyObjectList::insert function. Why?
Why do you want the specialization in the first place though? What is
the "specific processing", and why is template specialization the best
way for it to be carried out?
Finally, to answer your specific question, you could call:
return insert(&_Val, _Val + 1);
to call the unspecialized range version.
Tom
|