我有这堂课:
class MessageSender
{
private:
std::set<std::string> connectedUsers;
std::queue<std::string> messages;
std::list<std::unique_ptr<std::thread>> threads;
std::mutex mutex;
std::condition_variable condition_variable;
static const char* in_filename;
static const char* out_filename;
void checkNewMessages();
void sendAllMessages();
bool emptyFileIntoQueue(std::string filename);
重要部分:
typedef void (MessageSender::*func_t)();
typedef std::pair<func_t, const char*> funcPair_t;
// A vector that holds all functions and their explanations for the menu // null indicates exit option
const std::vector<funcPair_t> menuFunctions = {
funcPair_t(&MessageSender::menu_signIn, "Sign in to the messaging list."),
funcPair_t(&MessageSender::menu_signOut, "Sign out of the messaging list."),
funcPair_t(&MessageSender::menu_printConnectedUsers, "Show all connected users."),
funcPair_t(nullptr, "Exit the menu.") };
// Functions for the menu.
void menu_signIn();
void menu_signOut();
void menu_printConnectedUsers();
public:
MessageSender();
void launchMenu();
bool signIn(std::string username);
bool signOut(std::string username);
void printConnectedUsers() const;
};
正如您在重要部分中所看到的,我声明了vector
包含成员函数指针pair
和const char*
的{{1}}并在同一行初始化它。
我收到这个错误:&#34; &#39;&安培;&#39; :对绑定成员函数表达式的非法操作&#34;
编译器是VS 2013。