我试图外部内联函数。我认为它应该如何工作:
//a.cpp
inline void f(int) {}
//b.cpp
extern void f(int);
int main() { f(4); }
Run Code Online (Sandbox Code Playgroud)
但是出现链接错误。然后通过阅读此内容(“ 1inline ” ,必须在每个翻译单元中声明它。)。我试过的
//a.cpp
inline void f(int) {}
//b.cpp
extern inline void f(int);
int main() { f(4); }
Run Code Online (Sandbox Code Playgroud)
仍然出现链接错误。但是现在,尝试一些我不知道自己在做什么的事情:
//a.cpp
extern inline void f(int) {}
//b.cpp
extern inline void f(int);
int main() { f(4); }
Run Code Online (Sandbox Code Playgroud)
有用。这里发生了什么事?之前加入extern的一切,f在a.cpp有内在联系?
我正在将MSVC 2017(v141)与/permissive-和/std:c++17