E
esuvs81
Hi guys, is it possible to use partial specialization on individual
member functions of a class (rather than partially specializing the
whole class)? I have the following code:
#include <iostream>
template<typename T, typename U>
class MyClass
{
public:
void func(void);
};
template<typename T, typename U>
void MyClass<T,U>::func(void)
{
std::cout << "In generic function" << std::endl;
}
template<>
void MyClass<float,char>::func(void)
{
std::cout << "In function specialized on both types" << std::endl;
}
template<> template<typename U>
void MyClass<int,U>::func(void)
{
std::cout << "In function specialized on one type" << std::endl;
}
The last function doesn't work, the compiler gives me the following
error:
error C2244: 'MyClass<T,U>::func' : unable to match function definition
to an existing declaration
Is it just a syntactic error on my part, or is this prohibited fior
some reason.
To place it in context the real problem occurs in my Matrix class which
is paramatised on both size and data type. Most of the functions
(multiplication, transpose, etc) are generic but 2D, 3D, and 4D
rotation matrices are generated in different ways.
Anyway, any help appriciated,
David
member functions of a class (rather than partially specializing the
whole class)? I have the following code:
#include <iostream>
template<typename T, typename U>
class MyClass
{
public:
void func(void);
};
template<typename T, typename U>
void MyClass<T,U>::func(void)
{
std::cout << "In generic function" << std::endl;
}
template<>
void MyClass<float,char>::func(void)
{
std::cout << "In function specialized on both types" << std::endl;
}
template<> template<typename U>
void MyClass<int,U>::func(void)
{
std::cout << "In function specialized on one type" << std::endl;
}
The last function doesn't work, the compiler gives me the following
error:
error C2244: 'MyClass<T,U>::func' : unable to match function definition
to an existing declaration
Is it just a syntactic error on my part, or is this prohibited fior
some reason.
To place it in context the real problem occurs in my Matrix class which
is paramatised on both size and data type. Most of the functions
(multiplication, transpose, etc) are generic but 2D, 3D, and 4D
rotation matrices are generated in different ways.
Anyway, any help appriciated,
David