M
mark.mac
Hello,
I couldn't figure out how to specialize the following member template:
#include <iostream>
template <typename T1> class sample {
T1 value;
public:
sample(T1 v) : value(v) {}
template <typename T2> T1 val(T2 arg);
};
template <typename T1> template <typename T2> T1 sample<T1>::val(T2 arg)
{
return arg + value;
}
template <typename T1> template <> T1 sample<T1>::val(char arg)
{
return arg + value;
}
int main()
{
sample<int> s(0);
char c = 'a';
int i = 10;
std ::cout << s.val(c) << std::endl;
std::cout << s.val(i) << std::endl;
return 0;
}
I only want to partial specialize with T2 = char. Above gives error
"enclosing class templates are not explicitly specialized"
How do I fix this? Thanks.
Mark
I couldn't figure out how to specialize the following member template:
#include <iostream>
template <typename T1> class sample {
T1 value;
public:
sample(T1 v) : value(v) {}
template <typename T2> T1 val(T2 arg);
};
template <typename T1> template <typename T2> T1 sample<T1>::val(T2 arg)
{
return arg + value;
}
template <typename T1> template <> T1 sample<T1>::val(char arg)
{
return arg + value;
}
int main()
{
sample<int> s(0);
char c = 'a';
int i = 10;
std ::cout << s.val(c) << std::endl;
std::cout << s.val(i) << std::endl;
return 0;
}
I only want to partial specialize with T2 = char. Above gives error
"enclosing class templates are not explicitly specialized"
How do I fix this? Thanks.
Mark