Is it legal that a function pointer to "function with default arguments"?

Discussion in 'C++' started by Ajax Chelsea, Dec 2, 2003.

  1. Ajax Chelsea

    Ajax Chelsea Guest

    1,int (*f)(int a = 1);//is it legal?

    2,int (*f)(int a = 1);
    int g(int a = 2){return 0;}
    f = &g;//is it legal?
     
    Ajax Chelsea, Dec 2, 2003
    #1
    1. Advertisements

  2. Ajax Chelsea

    Ron Natalie Guest

    "Ajax Chelsea" <> wrote in message news:...
    > 1,int (*f)(int a = 1);//is it legal?
    >
    > 2,int (*f)(int a = 1);
    > int g(int a = 2){return 0;}
    > f = &g;//is it legal?


    First, default args have no affect on function type.
    int g(int a=2)
    has type int ()(Int) NOT int()()

    Second, default args are not allowed in pointer declarations.
    8.3.6 / 3 specifically covers it (and the point is driven home by the footnote
    that specifically says "This means that default arguments cannot appear,
    for example, in declarations of pointers to functions, references to functions, or
    typedef declarations."
     
    Ron Natalie, Dec 2, 2003
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. glen stark
    Replies:
    2
    Views:
    858
    Ron Natalie
    Oct 10, 2003
  2. Fraser Ross
    Replies:
    4
    Views:
    1,326
    Fraser Ross
    Aug 14, 2004
  3. Replies:
    10
    Views:
    990
    Chris Torek
    Feb 4, 2005
  4. murgan
    Replies:
    6
    Views:
    5,250
    Thad Smith
    Dec 21, 2005
  5. Vijai Kalyan
    Replies:
    4
    Views:
    1,079
    Vijai Kalyan
    Nov 8, 2005
  6. Replies:
    1
    Views:
    470
    Bob Hairgrove
    Mar 19, 2006
  7. Replies:
    3
    Views:
    461
    Philip Potter
    Apr 11, 2008
  8. Ingo
    Replies:
    2
    Views:
    654
Loading...