C++ curtiosity: default argument in a pointer to function.
This compiles and works under gcc 3.3.3, but I suspect it's not legal because I'm giving a default argument to a pointer to a function. Can anyone tell me if I'm right or wrong? #include<iostream> double function( double x, double y = 0 ){ return x * (x + y); } int main() { double (*function)( double, double = 0 ) = ::function; std::cout << function( 4 ) << std::endl; exit( 0 ); } -- JDL
On Monday 13 September 2004 17:05, John Lamb wrote:
This compiles and works under gcc 3.3.3, but I suspect it's not legal because I'm giving a default argument to a pointer to a function. Can anyone tell me if I'm right or wrong?
#include<iostream>
double function( double x, double y = 0 ){ return x * (x + y); }
int main() { double (*function)( double, double = 0 ) = ::function; std::cout << function( 4 ) << std::endl; exit( 0 ); }
-- JDL
My guess is you are wrong. Your code is right. A pointer is a scalar value, and I don't believe the language cares what it points to when it comes to initialization. -- Regards, Steven
participants (2)
-
John Lamb
-
Steven T. Hatton