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

A

Ajax Chelsea

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?
 
R

Ron Natalie

Ajax Chelsea said:
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."
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,148
Messages
2,570,838
Members
47,385
Latest member
Joneswilliam01

Latest Threads

Top