我不明白为什么会出现这个错误..
所有需要的lib已包含在其他.h
我有一个Rsh.h
:
class Rsh
{
private:
map<string, int(*)(const string &, FILE*)> supportedCmds;
public:
Rsh ();
~Rsh ();
void setup ();
};
和Rsh.cpp:
void Rsh::setup()
{
// Fill up list of supported commands
supportedCmds["cd"] = &Rsh::ashCd;
supportedCmds["ls"] = &Rsh::ashLs;
supportedCmds["pwd"] = &Rsh::ashPwd;
supportedCmds["history"] = &Rsh::ashHistory;
supportedCmds["exit"] = NULL;
}
输出g ++消息是这样的:
src/Rsh.cpp:24:26: error: assigning to 'mapped_type' (aka 'int (*)(const
std::__1::basic_string<char> &, __sFILE *)') from incompatible type 'int (Rsh::*)(const
string &, FILE *)'
supportedCmds["cd"] = &Rsh::ashCd;
^~~~~~~~~~~
src/Rsh.cpp:25:26: error: assigning to 'mapped_type' (aka 'int (*)(const
std::__1::basic_string<char> &, __sFILE *)') from incompatible type 'int (Rsh::*)(const
string &, FILE *)'
supportedCmds["ls"] = &Rsh::ashLs;
^~~~~~~~~~~
src/Rsh.cpp:26:26: error: assigning to 'mapped_type' (aka 'int (*)(const
std::__1::basic_string<char> &, __sFILE *)') from incompatible type 'int (Rsh::*)(const
string &, FILE *)'
supportedCmds["pwd"] = &Rsh::ashPwd;
^~~~~~~~~~~~
src/Rsh.cpp:27:29: error: assigning to 'mapped_type' (aka 'int (*)(const
std::__1::basic_string<char> &, __sFILE *)') from incompatible type 'int (Rsh::*)(const
string &, FILE *)'
supportedCmds["history"] = &Rsh::ashHistory;
^~~~~~~~~~~~~~~~
4 errors generated.
有什么建议吗?
已修复:map<string, int(Rsh::*)(const string &, FILE*)> supportedCmds;
感谢@WhiZTiM