Passing a pointer to a function inside a class

This is a discussion on Passing a pointer to a function inside a class within the C++ Programming forums, part of the General Programming Boards category; Hi Im having trouble passing a pointer to a function as another function's parameter: Code: void takesFuncPtr(bool (*func)()) {} class ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    84

    Passing a pointer to a function inside a class

    Hi

    Im having trouble passing a pointer to a function as another function's parameter:

    Code:
    void takesFuncPtr(bool (*func)()) {}
    
    class egg
    {
        bool fry();
        void passFry();
    };
    
    bool egg::fry() {}
    
    void egg::passFry()
    {
        takesFuncPtr(fry);
    }
    this is basicaly what im trying to do, and i think i know what the problem is, i cant have the address of something that hasnt been created yet, and because of that the compiler gives me an error.

    how can i get arround this problem??

    tks in advance.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,849
    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. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  4. Passing Pointer To Class In A Function
    By prog-bman in forum C++ Programming
    Replies: 11
    Last Post: 07-25-2004, 07:34 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM

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