c++ - Why can't I use float value as a template parameter? -


When I try to use float as a template parameter, the compiler This code cries, while int works fine.

Is this because I can not use the float as a template parameter?

  # include & lt; Iostream & gt; using namespace std; Template & lt; Class t, t default value & gt; Class Generic Class {Private: T-value; Public: Generic Class () {value = defaultValue; } T Returnal () {return value; }}; Int main () {GenericClass & lt; Int, 10 & gt; GcInteger; Generic Class & lt; Float, 4.6F & gt; GcFlaot; Cout & lt; & Lt; "The sum of integers \" is & lt; & Lt; GcInteger.returnVal (); Cout & lt; & Lt; "The sum of \ float \" is & lt; & Lt; GcFlaot.returnVal (); Return 0; }  

Error:

  main.cpp: function in `int main () ': Main.cpp: 25: Error:' float 'is not a valid type for a template static parameter main.cpp: 25: Error:'; 'Token key.cpp: 28: Error: request for member' returnee 'in `GCFLat', which is non-class type` int ' 

I "data structure ", author for game programmers by Ron Penton passes a float , but when I try it does not compile.

< "post-text" itemprop = "text">

existing C ++ standard to use the template as non- float (i.e., the actual number) or the character string does not allow the literal-type parameter you can definitely type float and four * type generic arguments Can use as

Perhaps the author is using a compiler that does not follow the current standard?


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -