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 

About non-type template-parameter

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





PostPosted: Fri Apr 15, 2005 11:59 pm    Post subject: About non-type template-parameter Reply with quote



Hi,everyone. I have a question about non-type template-parameter:

According to the standard, non-type template-parameter can be of
type "pointer to function", so the following template definitions:

template< class T, int(*func)(int) >
class Template1
{
// ...
};

template< class T, T(*func)(T) >
class Template1
{
// ...
};

should be leagal, right?
If the answer is yes, then which compiler(s) can handle that?
My VC6.0 at hand won't accept them :(

Thx!


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

Back to top
Alex Beluga
Guest





PostPosted: Sun Apr 17, 2005 2:21 pm    Post subject: Re: About non-type template-parameter Reply with quote



Probably because VC6 as usually wan't support standart well Sad
g++ and VC7.1 compiled all right.
As I can understand, you can pass these pointers to constructor.


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

Back to top
Ralph Zhang
Guest





PostPosted: Mon Apr 18, 2005 9:11 am    Post subject: Re: About non-type template-parameter Reply with quote



It's surely legal Smile
We all know that VC6 is not a good example for standard conformancy.
It compiles very well in VC7.1.


[ 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: Mon Apr 18, 2005 1:45 pm    Post subject: Re: About non-type template-parameter Reply with quote

Re: legality of pointer to function as non-type parameter

The standard limits non-type parameters to constant 'integral'
expressions
known at compile-time which includes the addresses of global objects
such as
functions.

So unfortunately floating point values are not legal and neither are
string
literals (although for good reasons).

Anyone serious about template programming should buy a copy of 'C++
Templates: the complete guide' by Josuttis and Vandevoorde in which all
these kinds of questions are answered.

---PMD

"Ralph Zhang" <ralph.zhang79 (AT) gmail (DOT) com> wrote

Quote:
It's surely legal Smile
We all know that VC6 is not a good example for standard conformancy.
It compiles very well in VC7.1.


[ 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.