The following code compiles properly.
#include <string>
template <typename T, typename U>
class Container
{
private:
T value1;
U value2;
public:
Container(){}
void doSomething(T val1, U val2);
};
template<typename T, typename U>
void Container<typename T, typename U>::doSomething(T val1, U val2)
{
; // Some implementation
}
template <>
class Container<char, std::string>
{
private:
char value1;
std::string value2;
public:
Container(){}
void doSomething(char val1, std::string val2)
{
; // Some other implementation
}
};
But if I try to define void doSomething(char val1, std::string val2)
outside, I get the following error.
#include <string>
template <typename T, typename U>
class Container
{
private:
T value1;
U value2;
public:
Container(){}
void doSomething(T val1, U val2);
};
template<typename T, typename U>
void Container<typename T, typename U>::doSomething(T val1, U val2)
{
; // Some implementation
}
template <>
class Container<char, std::string>
{
private:
char value1;
std::string value2;
public:
Container(){}
void doSomething(char val1, std::string val2);
};
template<>
void Container<char,std::string>::doSomething(char val1, std::string val2)
{
; // Some other implementation
}
Error:
Error 1 error C2910: 'Container::doSomething' : cannot be explicitly specialized c:\users\bharani\documents\visual studio 2005\projects\templates\template specialization\templatespecializationtest.cpp 35
What mistake do I commit?
Thanks.