Hi,
$4.3 talks about conversion of functions to pointers, specifically "An
lvalue of function type T...". My idea of "function type" is based on
the following article from Herb "http://www.ddj.com/cpp/184401824".
I wrote the following small piece of code.
// CODE SNIPPET 1
int *fn(int *p, const char& rc){return (int *)0;}
typedef int* MYFUNCTIONTYPE(int *, const char&);
void invoke(MYFUNCTIONTYPE t){
(t)(0, 'A');
}
void invoke(MYFUNCTIONTYPE *t){
(*t)(0, 'A');
}
int main(){
invoke(fn);
}
This code is ill-formed because the two versions of invoke are not
sufficiently different to be overloaded as complained by VS2008 and
Comeau.
However a slight modification to use typedef of function pointer,
makes the code perfectly well-formed as expected with the call
resolved to the first version of invoke.
// CODE SNIPPET 2
int *fn(int *p, const char& rc){return (int *)0;}
typedef int* (*MYFUNCTIONTYPE)(int *, const char&); // Changed
to typedef of Function Pointer Type
void invoke(MYFUNCTIONTYPE t){
(t)(0, 'A');
}
void invoke(MYFUNCTIONTYPE *t){
(*t)(0, 'A');
}
int main(){
invoke(fn);
}
So, basically I have two doubts:
a) Why is the first piece of code giving error?
b) $4.3- Does this section talk about the "function type" as in "CODE
SNIPPET 1" or as a more generic term and as interpreted in "CODE
SNIPPET 2"?
Regards,
Dabs
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|