ジェネリック関数ポインターを取得するにはどうすればよいですか。次のクラスを検討してください。
#ifndef PERSON_HPP_
#define PERSON_HPP_
#include <string>
class Person {
public:
Person() {
}
void SetName(std::string person_name) {
m_name = person_name;
}
void setDept(std::string dept_name) {
m_dept = dept_name;
}
void setAge(int person_age ) {
m_age = person_age;
}
std::string getName() {
return m_name;
}
std::string getDept() {
return m_dept;
}
int getAge() {
return m_age;
}
private:
std::string m_name;
std::string m_dept;
int m_age;
};
#endif
std::vector
関数ポインタをfor setName
、setDept
などconstructor
に格納したい...
通常の機能では、次を使用してこれを達成できます
#include <vector>
int mult(int a) {
return 2*a;
}
int main()
{
int b;
std::vector<void *(*)(void *)> v;
v.push_back((void *(*)(void *))mult);
b = ((int (*)(int)) v[0])(2); // The value of b is 2.
return 0;
}
私の場合は許可されていませんBoost
。