inline不成反蚀一小时

复制代码
$ cat a.cpp
#include <string>
#include <iostream>
using namespace std;
inline void fn() {
  string  s = "aaa\n";
  cout << s;
}
void bbb();
int main() { fn(); bbb(); }

$ cat b.cpp
#include <string>
#include <iostream>
using namespace std;
inline void fn() {
  string  s = "bbb\n";
  cout << s;
}
void bbb() { fn(); }

$ g++ -Wall a.cpp b.cpp
$ a.out
aaa
aaa
复制代码

在b.cpp中把inline去掉,结果是bbb bbb

a.cpp中也去掉inline:结果是:multiple definition of `fn()'

某个fn static或都static,应该,而且确实,aaa, bbb

还有这个:printf("%d %d\n"), $1.size(), $3.size();

posted @   Fun_with_Words  阅读(21)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
历史上的今天:
2022-01-04 又看到一本好书
2022-01-04 A Child's History of England.95
2022-01-04 A Child's History of England.94
2022-01-04 std::string的find挺慢的
2022-01-04 A Child's History of England.93
2022-01-04 A Child's History of England.92
2022-01-04 album









 和4张牌。

点击右上角即可分享
微信分享提示