Hassle with function pointers

This is a discussion on Hassle with function pointers within the C++ Programming forums, part of the General Programming Boards category; I have a weird problem with my function pointer Code: void (*test)(void)=0; void SetPointer(int pointer) { test=pointer; } This won't ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640

    Hassle with function pointers

    I have a weird problem with my function pointer

    Code:
    void (*test)(void)=0;
    
    void SetPointer(int pointer)
    {
         test=pointer;
    }
    This won't work
    I recieve this:

    '=' : cannot convert from 'int' to 'void (__cdecl *)(void)'

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Use
    Code:
    void SetPointer(void (*ptr)())
    {
       test = ptr;
    }

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    It works! thx.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  2. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM
  5. function pointers and member functions
    By thor in forum C++ Programming
    Replies: 5
    Last Post: 03-19-2002, 04:22 PM

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