我使用vs14编译器的函数模板有问题.因此,以下代码演示了该问题.
#include <iostream>
using namespace std;
class Class {
public:
int memberFoo() {
return 0;
}
};
template <class VariableT, class C>
void nothing(const VariableT C::*memberV) {
cout << "Pointer to member variable";
}
template <class R, class C>
void nothing(R (C::*memberF)()) {
cout << "Pointer to member function";
}
int main() {
nothing(&Class::memberFoo);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译器让我知道nothing
函数是模糊的.当我看到输出时,它似乎有其他行为超出我的预期.在第一个nothing
函数中,编译器推导VariableT
为int(void)
.实际上并不奇怪,但我认为第二个更合适并且会匹配.更有意思的是,如果const
在第一个重载函数中删除,程序将正确编译.你能建议我怎么处理这个吗?