Defining static const variables of a template class

后端 未结 2 1057
傲寒
傲寒 2020-12-21 17:31

I have a vector class which has some static const variables like ZERO. Now since vector is often implemented as a template class (and mine is no exception), I s

相关标签:
2条回答
  • 2020-12-21 18:01

    It's OK.

    Templates are a kind of way to tell the compiler to generate similar code for different types.
    This is exactly what it's for.

    0 讨论(0)
  • 2020-12-21 18:02

    No, that's perfectly legitimate and totally Standard. If you want to use a static variable in a templated class, there's no way you could possibly define all possible instantiations of it- those types may not even be nameable and therefore specializable. Hence, it's very necessary that template classes can have static variables defined for all possible uses.

    0 讨论(0)
提交回复
热议问题