Static variable inside template function

前端 未结 7 1937
一向
一向 2020-12-14 07:10

In C++, if you define this function in header.hpp

void incAndShow()
{
  static int myStaticVar = 0;
  std::cout << ++myStaticVar << \" \" <<         


        
7条回答
  •  旧时难觅i
    2020-12-14 07:14

    • templates will only actually be turned into code once they're instantiated (i.e. used)
    • headers are not to be used for implementation code, but only for declarations

提交回复
热议问题