| View previous topic :: View next topic |
| Author |
Message |
yyf Guest
|
Posted: Fri Apr 15, 2005 11:59 pm Post subject: About non-type template-parameter |
|
|
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
|
Posted: Sun Apr 17, 2005 2:21 pm Post subject: Re: About non-type template-parameter |
|
|
Probably because VC6 as usually wan't support standart well
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
|
Posted: Mon Apr 18, 2005 9:11 am Post subject: Re: About non-type template-parameter |
|
|
It's surely legal
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
|
Posted: Mon Apr 18, 2005 1:45 pm Post subject: Re: About non-type template-parameter |
|
|
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
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 |
|
 |
|