What are the requirements for C++ template parameters?

后端 未结 3 1777
無奈伤痛
無奈伤痛 2020-12-09 22:10

If you are using a template in C++ that takes an integer value as a parameter, are there any requirements on an integer variable used as the parameter that are different tha

3条回答
  •  借酒劲吻你
    2020-12-09 22:37

    It is always the case that the value of the int is needed at compile time.

    Since each template instantiation is a separate piece of compiled code (even for integer template paramaters) that integer needs to be available when compiled (and it must be guaranteed to never change).

    This is also why it's a good idea to not use integer template parameters when you are going to be using a large number of unique values - you can quickly end up with a huge executable file.

提交回复
热议问题