-
Notifications
You must be signed in to change notification settings - Fork 0
/
18.2.3.2.cc
55 lines (42 loc) · 1 KB
/
18.2.3.2.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <algorithm>
#include <iostream>
#include <string>
namespace mm{
class A{
public:
std::string mem;
};
void test(A, A){
std::cout << "mm::test(" << std::endl;
}
template <typename T>
void swap(T v1, T v2){
std::cout << "here" << std::endl;
using std::swap;
swap(v1.mem, v2.mem);
}
}
template <typename T>
void swap(T v1, T v2){
std::cout << "here" << std::endl;
using std::swap;
swap(v1.mem, v2.mem);
}
void test(mm::A, mm::A){
std::cout << "global" << std::endl;
}
void test2(){
using std::swap;
mm::A a;
mm::A b;
/* 标准库的 swap 没有右值引用,所以 用右值 会错误 */
/* 最近外层作用域 和 参数类型所在的作用域 一样好 */
swap(a, b);
}
int main(int argc, char const *argv[])
{
/* error: 参数所在的名字空间的函数 和 最近的外围作用域的函数 的 优先级 一样 */
using mm::test;
test(mm::A(), mm::A());
return 0;
}