64,648
社区成员
发帖
与我相关
我的任务
分享
# include <iostream>
using namespace std;
class Test
{
public:
void infor() { cout << "A" << endl; }
void infor(int a = 0) { cout << "B" << endl; }
};
int main()
{
typedef void (Test::*func)();
func f = &Test::infor;
Test a;
(a.*f)();
return 0;
}
# include <iostream>
using namespace std;
class Test
{
public:
void infor() { cout << "A" << endl; }
void infor(int a = 0) { cout << "B" << endl; }
};
int main()
{
Test a;
a.infor();
return 0;
}
g++ -Wall a.cpp -o a
a.cpp: In function ¡®int main()¡¯:
a.cpp:15: error: call of overloaded ¡®infor()¡¯ is ambiguous
a.cpp:8: note: candidates are: void Test::infor()
a.cpp:9: note: void Test::infor(int)
typedef void (Test::*Func)();
Func f = &Test::Infor;
(Test().*f)();