Template definition error

I have an issue converting VC++6 code to VC++ 2010. The following template function definition is not allowed by the new compiler:
1
2
3
4
5
6

template <> void AFXAPI DelElems <CBrush*> ( CPen** objects, int count ) {    
    for ( int i = 0; i < count; i++, objects++ )
        if (*objects)
            delete *objects;    
}


All errors refer to the header of the template function:
- syntax error : '<'
- syntax error : missing ';' before '<'
- 'DelElems' : illegal use of type 'void'
- unrecognizable template declaration/definition

What could be the possible reason for those error messages?
Thanks for your help!
Try the following

1
2
3
4
5
template void AFXAPI DelElems <CBrush*> ( CPen** objects, int count ) {    
    for ( int i = 0; i < count; i++, objects++ )
        if (*objects)
            delete *objects;    
}
No, unfortunately it doesn't function. I've got a tip I should distinguish between a template function specializition and its definition. The code I've posted is in a .cpp file. Should I specialize the template function in a header file?
Where are you using the template parameter CBrush*?
Shouldn't it have been DelElems <CPen*> ( CPen** objects ...

In general, avoid specializing function templates.

Just overload the function and be done with it.
void AFXAPI DelElems ( CPen** objects, int count )

See: http://www.gotw.ca/publications/mill17.htm
1
2
3
@relapse (2)
 
No, unfortunately 


I made a typo. Should be

template void AFXAPI DelElems <CBrush*> ( CBrush** objects, int count );
if you want to have explicit instantiation.

Topic archived. No new replies allowed.