C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Will function value bind to const reference in function temp

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
jakacki@cidc.com.cn
Guest





PostPosted: Mon Apr 18, 2005 11:04 am    Post subject: Will function value bind to const reference in function temp Reply with quote



Hello,

I would appreciate help and/or pointers to resources on the following
prolem: what does the Standard say about passing function
pointer/reference like this:


template <class F>
void get(const F& fun) {}

void f() {}

int main() { getFunction(f); }


* Is it legal?
* If so, what is the type of F inside make ?

These are the empirical results I got:

gcc-2.95:
OK, F is 'void ()()'

gcc-3.3.3:
no matching function for call to `get(void (&)())'

como-4.2.45.2:
no instance of function template "get" matches the argument list
The argument types that you used are: (void ())

como-4.3.3:
OK, F is 'void ()'

Any and all help appreciated.

Thank you in advance
Grzegorz


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
pmdoc
Guest





PostPosted: Wed Apr 20, 2005 9:14 am    Post subject: Re: Will function value bind to const reference in function Reply with quote



Section 8.3.5.4 [dcl.fct] states:

"A cv-qualifier-seq shall only be part of the function type for a non-static
member function, the function type to which a pointer to member refers or
the top level function type of a function typedef declaration"

It gives the example:

typedef void F();

struct S {
const F f; // not equivalent to void f() const
};

In the case of get(const F&) it makes no sense to pass a non-member
function, thus gcc 3.3.3 and como-4.2.45.2: are correct (I use VC++ 7.1
which also behaves correctly in flagging this as an error).

Remeber 'const' refers to the type of the hidden 'this' parameter in the
signature of member functions only.

-- PMD

<jakacki (AT) cidc (DOT) com.cn> wrote

Quote:
Hello,

I would appreciate help and/or pointers to resources on the following
prolem: what does the Standard say about passing function
pointer/reference like this:


template void get(const F& fun) {}

void f() {}

int main() { getFunction(f); }


* Is it legal?
* If so, what is the type of F inside make ?

These are the empirical results I got:

gcc-2.95:
OK, F is 'void ()()'

gcc-3.3.3:
no matching function for call to `get(void (&)())'

como-4.2.45.2:
no instance of function template "get" matches the argument list
The argument types that you used are: (void ())

como-4.3.3:
OK, F is 'void ()'

Any and all help appreciated.

Thank you in advance
Grzegorz

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.