#include <iostream>
#include <string>
#include <algorithm>
int main()
{
std::string str1 = "good", str2 = "luck";
swap(str1,str2); /*Line A*/
int x = 5, y= 3;
swap(x,y); /*Line B*/
}
Run Code Online (Sandbox Code Playgroud)
如果我评论B行代码编译(http://www.ideone.com/hbHwf),而注释行A代码无法编译(http://www.ideone.com/odHka),我收到以下错误:
error: ‘swap’ was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
为什么我在第一种情况下没有收到任何错误?