Does C++ 98 support partial template specification?
The following code compiles fine under C++ 11, but doesn't compile in Visual C++ 6.0.
So I am wondering if the syntax needs to be slightly different or if it's just not supported:
#include <iostream>
#include <string>
template <typename A, typename B> class Foo
{
public:
static void bar(A a, B b)
{
std::cout << "A";
};
};
template <typename A> class Foo<A, std::string>
{
public:
static void bar(A a, std::string b)
{
std::cout << "B";
};
};
template <typename B> class Foo<std::string, B>
{
public:
static void bar(std::string a, B b)
{
std::cout << "C";
};
};
template <> class Foo<std::string, std::string>
{
public:
static void bar(std::string a, std::string b)
{
std::cout << "D";
};
};
int main(int argc, char* argv[])
{
Foo<int, int>::bar(12, 42);
Foo<int, std::string>::bar(12, "");
Foo<std::string, int>::bar("", 42);
Foo<std::string, std::string>::bar("", "");
return 0;
}
Error Message:
Compiling...
Test.cpp
C:\test\test.cpp(20) : error C2989: 'Foo<A,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >' : template class has already been defined as a non-template class
C:\test\test.cpp(20) : error C2988: unrecognizable template declaration/definition
C:\test\test.cpp(29) : error C2989: 'Foo<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,A>' : template class has already been defined as a non-template class
C:\test\test.cpp(29) : error C2988: unrecognizable template declaration/definition
Error executing cl.exe.
Test.obj - 4 error(s), 0 warning(s)
Microsoft Visual C++ 6.0 does not support partial template specialisation. It is a known bug.
For more known standard compliance issues of VC++6.0, see here.
Archive links, since these KB articles seem to be removed from Microsoft databases