我米試圖定義一個「通用」指針,它指向可以用於一個特定的類內訪問各種部件的功能如下的成員函數:指針成員函數與升壓::變體
class Security{
inline std::vector<double> member_function(const std::string &input_data_string){ return ... a vector<double>....;};
};
我通過使用boost :: variant定義一個通用指針指向一個成員函數,該函數可以用於訪問「OTHER」函數以及不同的返回類型以及不同的類型參數。
typedef boost::variant<std::string,double, std::vector<double>, std::vector<std::string>> (Security::*ptr_sec_fn)(boost::variant<std::string,double, std::vector<double>, std::vector<std::string>>);
然後分配指針成員函數
ptr_sec_fn=&Security::member_function;
這是我得到的錯誤:
cannot convert from 'std::vector<_Ty> (__thiscall Security::*)(const std::string &)' to 'boost::variant<T0_,T1,T2,T3> (__thiscall Security::*)(boost::variant<T0_,T1,T2,T3>)'
1> with
1> [
1> _Ty=double
1> ]
1> and
1> [
1> T0_=std::string,
1> T1=double,
1> T2=std::vector<double>,
1> T3=std::vector<std::string>
1> ]
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
能否請你幫我鑑定我在做什麼這裏錯了嗎?非常感謝。
您是否考慮過使用'boost :: function'或'std :: function'來代替? – AJG85
也看'boost :: bind'和'boost :: phoenix :: bind' – Smash