Monday, November 27, 2006

Unspecialized class template can't be used ...

Ever had fun with Compiler Error C3203 and Visual Studio 2005 (VC8)? I maintain a project that uses the Windows Template Library (WTL). When upgrading the project to use VC8 I noticed hundreds upon hundreds of compile errors with this cryptic statement "unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type".

Here's Microsoft's explanation:
Here's my translation:

Say you have a class definition something like below. Pay attention to the text in bold.

template <class TItem = CCustomTabItem>
class CDotNetButtonTabCtrl :
public CCustomTabCtrl<CDotNetButtonTabCtrl, TItem>

Change the code to below so it will compile, and your C3203 compile errors will disappear.

template <class TItem = CCustomTabItem>
class CDotNetButtonTabCtrl :
public CCustomTabCtrl<CDotNetButtonTabCtrl<TItem>, TItem>


Anonymous said...

Thank you very much! You've helped me further with my transition to VS2005. You don't happen to have a fix for error C2990, do you?

- Frans

koobmeej said...

Your welcome! As for C2990 , I haven't encountered that issue yet. From Microsoft's description it looks like that error occurs when a class is declared as a template, and then redeclared without the template.
So from Microsoft's example, somewhere in the code a template class is declared.

template <class T>
class C{};

Then somewhere else the class is redefined without the template

class C{}; // C2990