刚入坑,只会控制台操作
我想用函数指针组成的数组来实现“选择输出”,就是用户从一些信息之中挑几个输出。但在构建函数指针的时候出现了问题,程序无法构建
我写的关于函数指针的代码如下(在main中):
通过不断注释构建的方法,出现在中间注释掉的两行(原本想用数组构建,后来发现不行又改用普通变量构建函数指针,但还是无法构建)
typedef void (See::* out)(int);
//out outArr[9] = { &See::name, &See::sex, &See::age, &See::position, &See::serviceLength, &See::number, &See::salary, &See::lastChangedSalary, &See::allChangedSalary };
//out outArr = &See::name;
See* use = new See;
//(use->*outArr[0])(1);//测试
我的see类如下:
class See {
private:static std::vector<People> arr;
public:
void getArr(std::vector<People> arr) {
this->arr = arr;
}
void name(int place) {
std::cout << "姓名:" << arr[place].getName() << '\n';
}
void sex(int place) {
std::cout << "性别:" << arr[place].getSex() << '\n';
}
void age(int place) {
std::cout << "年龄:" << arr[place].getAge() << '\n';
}
void position(int place) {
std::cout << "职位:" << arr[place].getPosition() << '\n';
}
void serviceLength(int place) {
std::cout << "工龄:" << arr[place].getServiceLength() << '\n';
}
void number(int place) {
std::cout << "电话:" << arr[place].getNumber() << '\n';
}
void salary(int place) {
std::cout << "薪资:" << arr[place].getSalary() << '\n';
}
void lastChangedSalary(int place) {
std::vector<People::changedSalary> low = arr[place].getChangedSalary();
std::cout << "薪资变化:" << low[low.size() - 1].money << '\n';
}
void allChangedSalary(int place) {
std::cout << "该员工全部薪资变化如下:\n时间:\t变化金额:\n";
std::vector<People::changedSalary> low = arr[place].getChangedSalary();
for (int i = 0; i < low.size(); i++) {
std::cout << low[i].time << "\t" << low[i].money << "\n";
}
}
};
不知道出现了什么问题