Static function declared but not defined in C++

后端 未结 7 1977
小鲜肉
小鲜肉 2020-12-23 18:50

I\'m getting an error from the following code using C++.

Main.cpp

#include \"file.h\"

int main()
{
   int k = GetInteger();
   retu         


        
7条回答
  •  执笔经年
    2020-12-23 19:09

    Because in this case, static means that the name of the function has internal linkage; that GetInteger in one translation unit is unrelated to GetInteger in any other translation unit. The keyword static is overloaded: in some cases, it affects lifetime, and in others, binding. It's particularly confusing here, because "static" is also the name of a lifetime. Functions, and data declared at namespace scope, always have static lifetime; when static appears in their declaration, it causes internal binding, instead of external.

提交回复
热议问题