-
template specialization compile error on MSVC.NET 2003
This code below can compile properly on MSVC 6.0 but cannot on MSVC .NET 2003. Does anyone know what's going on ??
Code:
template <class T, class U>
void ReadRNet(int& a, U** b, T* c = NULL)
{
// DO something here.
return;
}
template<>
void ReadRNet<int, char*>(int& a, char* b)
{
// Do something here.
return;
}
// error C2912: explicit specialization; 'void ReadRNet<int,char*>(int&,char** )' is not a specialization of a function template
-
correct error message above.
Code:
template <class T, class U>
void ReadRNet(int& a, U** b, T* c = NULL)
{
// DO something here.
return;
}
template<>
void ReadRNet<int, char*>(int& a, char* b)
{
// Do something here.
return;
}
// error C2912: explicit specialization; 'void ReadRNet<int,char*>(int&,char* )' is not a specialization of a function template
-
6 is less than standard and forgives a lot of "not quite correct" code. When in doubt, .net is normally correct.
I think you need the template args in the <> on the bottom one?
-
You can't define a partial specialization of a function template in C++. This is possible only with class templates. You can however define an *overloaded* version of the said function, which means that you should get rid of the template <>
part, and that would turn the "specialization" into an ordinary overloaded functions. In general if Visual 7.0 rejects code that compiled fine under VC++ 6, it's right.
Danny Kalev
-
Danny, what's partial & fully specialization ?
-
a partial specialization selects a subset of the template instances from the primary template. So if you have a template X<T>, in which T can be any type, a partial specialization thereof can look like X<T*> which applies only to pointers, but this is still an infinitr set of template specializations (i.e., instances) because you can define an endless number of pointer types. A full specialization is simply a template instance: X<int>, X<char*> etc.
You can read more about this here:
http://www.informit.com/guides/conte...plus&seqNum=49
and
http://www.informit.com/guides/conte...plus&seqNum=50
Last edited by Danny; 11-17-2005 at 07:54 AM.
Danny Kalev
Similar Threads
-
Replies: 2
Last Post: 07-26-2005, 07:41 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks