Pointers to partially specialized template methods, type confusion

M

Martin Magnusson

I have a partially specialized templated class, which at one point needs
to pass pointers to some of its methods to another function. However, it
seems that my compiler (gcc) and me don't quite agree on the types for
the methods.

In the code below, the constructor to NLF2 (near the bottom) takes as
its last two arguments two function pointers of type void(*)(...), and
apparently &PR<2>::pR_init is of type void(PR<2>::*)(...).

If I remove the partial specialization, and just leave a general
implementation of PR, it works.

Does anyone know what I'm missing here? (The NLF class comes from the
OPT++ library for numerical optimization)

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
#include "OPT/NLF.h"
#include "OPT/NLP.h"

template< int TD >
class PR;

const int D = 2;
class PR<D>
{
public:
void init();

private:
void PR_function(int mode, int ndim,
const ColumnVector& x,
real& fx,
ColumnVector& gx,
SymmetricMatrix& Hx, int& result );
void PR_init(int dim, ColumnVector& parameters);
};

//template<int D>
void PR<D>::pR_function(int mode, int ndim,
const ColumnVector& x,
real& fx,
ColumnVector& gx,
SymmetricMatrix& Hx, int& result) {}

//template<int D>
void PR<D>::pR_init(int dim, ColumnVector& parameters) {}

//template<int D>
void PR<D>::init()
{
NLF2 optimizer
(3, &PR<2>::pR_function, &PR<2>::pR_init );
//======== ERROR ON THE LINE ABOOVE =========
}


int main()
{
PR<2> pr;
pr.init();
return 0;
}

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
 
R

Rob Williscroft

Martin Magnusson wrote in @posting.google.com in comp.lang.c++:
In the code below, the constructor to NLF2 (near the bottom) takes as
its last two arguments two function pointers of type void(*)(...), and
apparently &PR<2>::pR_init is of type void(PR<2>::*)(...).

The function expects normal functions, i.e. non-member or static-member
functions, you are passing non-static member function's.

Make the member's static or move them out of the class.

HTH.

Rob.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top