我知道内联函数是将其主体插入到调用它们的位置的函数.那么为什么调用它们时不会受范围更改影响的内联函数:
#include <iostream>
inline void alert(const std::string &str) { cout << str; }
int main() {
using namespace std;
alert("Hello World"); // cout << "Hello World";
}
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为我得到错误cout was not declared in this scope,但如果我这样std::cout做.如果内联函数的函数体插入到作用域中,为什么C++不知道它cout是否是成员std?