Community
cancel
Showing results for 
Search instead for 
Did you mean: 
gert_massa
Beginner
205 Views

Error on partial template specialization

Jump to solution
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
205 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

3 Replies
Judith_W_Intel
Employee
206 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

gert_massa
Beginner
205 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?
Judith_W_Intel
Employee
205 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
Reply