Static function declared but not defined in C++

后端 未结 7 2021
小鲜肉
小鲜肉 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:15

    In C++, static at global/namespace scope means the function/variable is only used in the translation unit where it is defined, not in other translation units.

    Here you are trying to use a static function from a different translation unit (Main.cpp) than the one in which it is defined (File.cpp).

    Remove the static and it should work fine.

提交回复
热议问题