By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,089 Members | 1,361 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,089 IT Pros & Developers. It's quick & easy.

Pointers to partially specialized template methods, type confusion

P: n/a
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;
}

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Martin Magnusson wrote in news:35e171fa.0411230104.7cecc7b2
@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.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.