Pointers to partially specialized template methods, type confusion

From: Martin Magnusson (loveslave_at_frustratedhousewives.zzn.com)
Date: 11/23/04


Date: 23 Nov 2004 01:04:37 -0800

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;
}

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////



Relevant Pages

  • Re: Malloc code
    ... int xxx; ... As for not using the void pointer, I will have to do some further testing ... I just needed some insight on passing arrays of pointers. ... struct MCB *r1; ...
    (microsoft.public.vc.language)
  • Re: Using a link list over an array.
    ... compile (p->data is a void *) so you have not shown us some key ... You can't use it to sort a list of ints where the int is ... You can use it to sort a list of pointers to any type. ...
    (comp.lang.c)
  • Re: void *
    ... list_add_head(&p, (int *)100); ... That was my understanding of 'void *' concept. ... In fact at your level the first thing you should assume when you appear to need a cast is that you have done something wrong and a cast is *not* the solution. ... Personally I don't think you understand the concept of pointers yet, so you need to read the sections of your text book and the comp.lang.c FAQ that refer to pointers. ...
    (comp.lang.c)
  • Re: How are C++ objects laid out in memory ?
    ... > void print(); ... int main ... > But the function pointers declared in above MsgStruct structure have ... > pointers which I can locate and then invoke the function pointers? ...
    (comp.lang.asm.x86)
  • Re: "Pointers" and "by reference" do my head in!
    ... that way we coul have explained things in the terms you are used to ... > Or am I going to have to bite the bullet and grapple with pointers? ... /* this function takes an int as its argument, ... > void test_function ...
    (alt.comp.lang.learn.c-cpp)