大家经常犯的一个错误 函数调用缺少参数列表;请使用“&Student::Printf”创建指向成员的指针
例如代码:
#include<iostream>
using namespace std;
struct Student
{
char _name[20];
char _sex[6];
int _age;
void InitStudent(char* pname, char* psex, int age)
{
strcpy_s(_name, pname);
strcpy_s(_sex, psex);
_age = age;
}
void Printf()
{
cout << _name << " " << _sex << " " << _age << endl;
}
};
int main()
{
Student std1;
std1.InitStudent("dandna", "women", 20);
std1.Printf;
system("pause");
return 0;
}
编译后提示:
这是因为在调用Printf时忘记加括号。正确的是std.Printf()