c++模版函数delete防止隐士类型转换.md

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
struct Person {
int a = 0;
operator int&() { return a; }
operator const int&() const { return a; }
};

template <typename T>
void testFunc(T arg) = delete;

void testFunc(int arg)
{
printf("called testFunc int\n");
}

int main() {

Person a;
testFunc(a); //报错
return 0;
}