C ++ programming language, 3E, section 7.7, p. 159:
You can take the address of an overloaded function by assigning or initializing a pointer to a function. In this case, the target type is used to select from a set of overloaded functions. For example:
void f(int); int f(char); void (*pf1)(int) = &f;
As far as I know (not tested), the same goes for member functions. Thus, the solution should probably be split into two lines:
connect((&GApp::foo)(double));
becomes:
void (GApp::*tmp)(double) = &GApp::foo; connect(tmp);
Never call tmp variables; -)
I would suggest that newacct cast is also safe for the same reason. Casting on void (GApp::*)(double) is defined the same as initializing the temporary type void (GApp::*)(double) . Since the expression used to initialize it is &GApp::foo , I would expect the same magic to apply to the cast, applicable to any other initialization with an overloaded function. Stroustup does not say “initializing a function pointer variable”, he says “initializing a function pointer”. Thus, this should include temporary files.
So, if you prefer single line:
connect((void (GApp::*)(double))(&GApp::foo));
However, I assume that the standard has the same idea of consistency as I did, and I have not tested it.
Steve jessop
source share