By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,421 Members | 1,089 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,421 IT Pros & Developers. It's quick & easy.

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

P: n/a
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?
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Ajax Chelsea" <aj*********@163.com> wrote in message news:62**************************@posting.google.c om...
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."
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.