Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > "Function Types...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 9821 of 9909
Post > Topic >>

"Function Types"

by rkldabs@[EMAIL PROTECTED] Jul 23, 2008 at 07:28 AM

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! ]
 




 3 Posts in Topic:
"Function Types"
rkldabs@[EMAIL PROTECTED]  2008-07-23 07:28:18 
Re: "Function Types"
Thomas Richter <thor@[  2008-07-23 19:37:08 
Re: "Function Types"
Jiang <goo.mail01@[EMA  2008-07-24 02:36:57 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Aug 20 13:12:33 CDT 2008.