'float' is invalid template constant parameter error.

corey taylor corey.taylor@gmail.com
Tue May 31 20:29:00 GMT 2005


Bart,

  According to section 14.3.2 paragraph 1 of the C++ specification:

A template-argument for a non-type, non-template template-parameter
shall be one of:
— an integral constant-expression of integral or enumeration type; or
— the name of a non-type template-parameter; 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 if the
corresponding template-parameter is a reference;
or
— a pointer to member expressed as described in 5.3.1 .


You should note the first listed item (integral or enumeration type).

corey

On 5/31/05, Jenkins, Bart (NE) <Bart.Jenkins@gd-ais.com> wrote:
> All,
>   Here is a bit of code, boiled down to it's essence, that works fine in both Visual C++ 6.0 sp 6 and Intel for Windows 8.1 but fails in GCC 3.2.3 and 3.4:
> 
> AdaNumeric_T.cpp
> --------------
> 
> template <typename T, T delta_val>
> class AdaNumeric_T
> {
> private:
>   T t;
> };
> 
> typedef AdaNumeric_T<int,1> AdaIntType;
> typedef AdaNumeric_T<float,1.0> AdaFloatType;
> 
> int main(int argc, char* argv[])
> {
>   return 0;
> }
> 
> 
> 
> (Please ignore the fact that I don't do anything with 'delta_val' and nothing is getting assigned to 'T t')
> 
> THE PROBLEM:
> 
> The typedef 'typedef AdaNumeric_T<int,1> AdaIntType;' works fine but the version right beneath it with the float type does not.  I get a:
> 
> "'float' is not a valid type for a template constant parameter"
> 
> Which seems strange.
> 
> Is the Intel compiler more ANSI compliant than GCC or is this a bug in GCC?  Does this work in GCC 4.0?
> 
> TIA
> 
> Bart Jenkins
> ph: (703) 263-2883
> General Dynamics
> Advanced Information Systems
> 12450 Fair Lakes Circle
> Fairfax, VA 22033
> 
> 
>


More information about the Gcc-help mailing list