Function pointer as the parameter

This is a discussion on Function pointer as the parameter within the C++ Programming forums, part of the General Programming Boards category; I followed the NAG example for optimation. The main function is: void nag_opt_nlp(int n, int nclin, int ncnlin, double a[], ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    3

    Question Function pointer as the parameter

    I followed the NAG example for optimation. The main function is:

    void nag_opt_nlp(int n, int nclin, int ncnlin, double a[], int tda, double bl[], double bu[],
    void (*objfun)(int n, double x[], double *objf, double g[], Nag_comm * comm),
    void(*confun)(int n, int ncnlin, int needc[], double x[], double conf[], double conjac[], Nag_Comm *comm),
    double x[], double *objf, double g[],
    Nag_E04_Opt *options, Nag_Comm *comm, NagError *fail)

    In the manual example, the call of the objective function 'objfun' is directly objfun, yet my compiler returns an error of:

    error of parameter 8: can't convert void(int,double [],double *,double [], Nag_comm*) to void(_stdcall *)(int*, double*, double*,double*,Nag_comm*)

    I really have no idea how to tackle this. Anyone can help? Many thanks!

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,420
    Dunno - your error message and code are inconsistent.

    > void (*objfun)(int n, double x[], double *objf, double g[], Nag_comm * comm)
    First parameter is an int in the function pointer declaration in the prototype of nag_opt_nlp

    > can't convert void(int,double [],double *,double [], Nag_comm*)
    What you appeared to try and pass as a parameter matches that.

    > void(_stdcall *)(int*, double*, double*,double*,Nag_comm*)
    What it claimed it wanted doesn't match.
    The first parameter is int*, not int
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    3
    Sorry! Just a typeout error. It is int.

    error C2664: cannot convert parameter 8 from 'void (int, double [], double *, double [], struct comm_struct *)' to
    'void (_stdcall *)(long, double *,double*,double *, struct comm_struct *)'

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,420
    > Sorry! Just a typeout error. It is int.
    Well don't make typo's then!
    Copy/paste what you can actually see.

    Well there's the answer then - one param is int, the other is long.

    Make them consistent.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is a virtual function pointer?
    By ting in forum C++ Programming
    Replies: 4
    Last Post: 03-05-2008, 01:36 AM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  3. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM
  5. function pointer & Thread Parameter :: Multithreading
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 09-11-2002, 08:42 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21