Template strangeness
I''m really curious about something... When you declare templates, you can do things like:
template int test()
{
return N;
}
And it compiles just fine; but when you replace the int with a float or double it doesn''t compile O_o. Why is this?
quote:Original post by Puzzler183
I'm really curious about something... When you declare templates, you can do things like:
template int test()
{
return N;
}
And it compiles just fine; but when you replace the int with a float or double it doesn't compile O_o. Why is this?
Because a non-type template parameter must be of one of the following
— an integral constant-expression of integral or enumeration type; or
— the name of a non-type template-parameter; or
— the name of an object or function with external linkage, including function templates and function
template-ids but excluding non-static class members, expressed as id-expression; or
— the address of an object or function with external linkage, including function templates and function
template-ids but excluding non-static class members, expressed as & id-expression where the & is
optional if the name refers to a function or array; or
— a pointer to member
As specified in 14.3.2 of the C++ standard
[edited by - Jingo on November 29, 2003 8:40:30 PM]
quote:Original post by Jingo
Because a non-type template parameter must be of one of the following
— an integral constant-expression of integral or enumeration type; or
— the name of a non-type template-parameter; or
— the name of an object or function with external linkage, including function templates and function
template-ids but excluding non-static class members, expressed as id-expression; or
— the address of an object or function with external linkage, including function templates and function
template-ids but excluding non-static class members, expressed as & id-expression where the & is
optional if the name refers to a function or array; or
— a pointer to member
As specified in 14.3.2 of the C++ standard
[edited by - Jingo on November 29, 2003 8:40:30 PM]
But you didn''t answer my question... I know the standard says so, but why? What is the point of restricting things like that?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement