0

I have a problem, where I can not instantiate a template with the type float, allthough it works just fine with an int.

The following code shows my problem:

template<typename T, T v>
struct Test
{
    constexpr static T value = v;
};

int main()
{
    Test<int,   1   >::value;
    Test<float, 1.0f>::value;

    return 0;
}

This program compiles perfectly fine, as long only the instantiation with int is present - as soon as I add the second line with float, the compilation failes with the error: " C993: 'float': illegal type for non-type parameter 'v' ". Does anybody have an idea on how to solve the problem and make it compile with float?

I am using MSVC and C++17.

Sincerely,

Lehks

Lehks
  • 2,582
  • 4
  • 19
  • 50
  • 1
    Floating-point types can't appear as a template parameter. That's that. – DeiDei May 04 '18 at 16:30
  • Look at: http://en.cppreference.com/w/cpp/language/template_parameters, at the part where it list parameter list: _type is one of the following types (optionally cv-qualified, the qualifiers are ignored): (...) integral type; (...)_ – Amadeus May 04 '18 at 16:32
  • Thank you very much, you two! – Lehks May 04 '18 at 16:34

0 Answers0