Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Follow us on Facebook Follow us on Twitter Linked In Flickr Watch us on YouTube Google+
Results 1 to 2 of 2
  1. #1
    Junior Member JohnLenning's Avatar
    Join Date
    May 2011
    Posts
    0
    Downloads
    0
    Uploads
    0

    Newbie Function Question.?

    I don't understand what the double ints are for like in:
    int operation (int x, int y, int (*functocall)(int,int))

    What does this mean?
    int (*minus)(int,int) = subtraction;


    // pointer to functions
    #include <iostream>
    using namespace std;

    int addition (int a, int b)
    { return (a+b); }

    int subtraction (int a, int b)
    { return (a-b); }

    int operation (int x, int y, int (*functocall)(int,int))
    {
    int g;
    g = (*functocall)(x,y);
    return (g);
    }

    int main ()
    {
    int m,n;
    int (*minus)(int,int) = subtraction;

    m = operation (7, 5, addition);
    n = operation (20, m, minus);
    cout <<n;
    return 0;
    }

  2. #2
    Senior Member JoelKatz's Avatar
    Join Date
    Jun 2008
    Posts
    102
    Downloads
    0
    Uploads
    0
    int operation (int x, int y, int (*functocall)(int,int))
    This means that 'operation' is a function that returns an integer (that's the 'int operation (' part). It takes as parameters two integers, called 'x' and 'y' (that's the 'int x, int y' part), and a pointer to a function called 'functocall' which returns an integer and takes two integers (that's the 'int (*functocall)(int,int)' part).

    int (*minus)(int,int) = subtraction;
    This creates a pointer called 'minus' (that's the '*minus' part). It points to a function takes two integers as parameters and returns one (that's the 'int' and '(int,int)' parts). The pointer initially points to the function named 'subtraction' (that's the '=subtraction' part).

    Hope that helps.


Similar Threads

  1. Replies: 1
    Last Post: 09-28-2011, 04:05 AM
  2. Replies: 0
    Last Post: 01-24-2011, 06:17 PM
  3. Replies: 2
    Last Post: 10-21-2010, 06:19 PM
  4. Replies: 0
    Last Post: 10-16-2010, 05:16 PM
  5. Replies: 1
    Last Post: 12-16-2009, 05:40 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -4. The time now is 09:11 PM.
Powered by vBulletin® Version 4.2.5
Copyright © 2024 vBulletin Solutions Inc. All rights reserved.