Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

Error on partial template specialization

gert_massa
Beginner
822 Views
I'm unable to use partial template specializations in my code using the intel 11.0.72 compiler on win32.

my full template looks like this:

template
void Matrix::Avarage()

But when i want to use a partial specialization on the folowing line

template
void Matrix ParallelMode::MPI>::Avarage()

I get the folowing error

error: template argument list must match the parameter list

Any suggestions?

0 Kudos
1 Solution
Judith_W_Intel
Employee
822 Views

In C++ function templates cannot be partially specialized, but class
templates can. Therefore, the workaround is to make a single generic
function template that calls a member function of a generic class
template. Then write a partial specialization for the class template
that does what you want. In other words write a specialization of the Matrix class
like this:

template _MODE>
class Matrix {
public:
void Avarage();
};

template
class Matrix
{
public:
void Avarage();
};


template _MODE>
void Matrix::Avarage() {;}

template
void Matrix::Avarage() {;}

View solution in original post

0 Kudos
3 Replies
Judith_W_Intel
Employee
823 Views

In C++ function templates cannot be partially specialized, but class
templates can. Therefore, the workaround is to make a single generic
function template that calls a member function of a generic class
template. Then write a partial specialization for the class template
that does what you want. In other words write a specialization of the Matrix class
like this:

template _MODE>
class Matrix {
public:
void Avarage();
};

template
class Matrix
{
public:
void Avarage();
};


template _MODE>
void Matrix::Avarage() {;}

template
void Matrix::Avarage() {;}

0 Kudos
gert_massa
Beginner
822 Views
Thanks Judith!

But one more question. Should I repeat the complete matix definition (like all other member fuctions and the member variables) for each partial specialization?
0 Kudos
Judith_W_Intel
Employee
822 Views
Quoting - gert.massa
Thanks Judith!

But one more question. Should I repeat the complete matix definition (like all other member fuctions and the member variables) for each partial specialization?

It would probably be easier to use the generic template class as a base class for any functions that don't need to be partly specialized, i.e.:

template
class Matrix :
public Matrix
0 Kudos
Reply