Thread: Passing a pointer to a function inside a class

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

    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
    39,664
    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.

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, 08: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, 06:34 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM