Thread: typedef a function pointer question..

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    47

    typedef a function pointer question..

    Code:
    typedef void (*fp)(int i, int j);
    
    void typedef_func(int i, int j)
    {
    	cout << "i = " << i << " : j + " << j << endl;
    }
    
    int main()
    {
    	fp obj;
    	obj(5,6);
    
    	return 0;
    }
    from my understanding the above should work. but i can't seem to get it to work. please help out ..

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Your function pointer named obj was not initialised to point to typedef_func.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    47
    AAAAAAHhhhhhhhhh
    silly me.. learnt something new.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Typedef representing pointer to function
    By pdc in forum C Programming
    Replies: 3
    Last Post: 06-10-2005, 10:10 AM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM