|
源文件如下:
- 1 #ifndef _USERLOGIN_PROTOCOL_H
- 2 # define _USERLOGIN_PROTOCOL_H
- 3
- 4 #include "protocols.h"
- 5
- 6 //typedef int (*pro_Action)(int);
- 7
- 8 class protocolController
- 9 {
- 10 public:
- 11 protocolController();
- 12 private:
- 13 //pro_Action action[30];
- 14 int (protocolController::*action[30])(int) const;
- 15
- 16 int action_NULL(int signal) const;
- 17 int action_ServerStatus(int signal) const;
- 18 int action_LoginUsername(int signal) const;
- 19 int action_LoginPassword(int signal) const;
- 20 int action_RegisterUsername(int signal) const;
- 21 int action_RegisterPassword(int signal) const;
- 22 int action_RegisterEmail(int signal) const;
- 23 };
- 24
- 25 typedef int (protocolController::*pro_Action)(int);
- 26 #endif
复制代码
- 1 #include "protocolController.h"
- 2 #include "protocols.h"
- 3 #include <string.h>
- 4
- 5 protocolController::protocolController()
- 6 {
- 7 for (int i = 0; i < 30; i++)
- 8 {
- 9 action[i] = &(protocolController::action_NULL);
- 10 }
- 11 action[C_BEDEFINE_0] = &action_NULL;
- 12 action[C_SERVER_STATUS] = &action_ServerStatus;
- 13 action[C_LOGIN_USERNAME] = &action_LoginUsername;
- 14 action[C_LOGIN_PASSWORD] = &action_LoginPassword;
- 15 action[C_REGISTER_USERNAME] = &action_RegisterUsername;
- 16 action[C_REGISTER_PASSWORD] = &action_RegisterPassword;
- 17 action[C_REGISTER_EMAIL] = &action_RegisterEmail;
- 18 }
复制代码
编译结果如下:
- $ g++ -c protocolController.cpp -o protocolController.o
- protocolController.cpp: In constructor 'protocolController::protocolController()':
- protocolController.cpp:9: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say '&protocolController::action_NULL'
- protocolController.cpp:11: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say '&protocolController::action_NULL'
- protocolController.cpp:12: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say '&protocolController::action_ServerStatus'
- protocolController.cpp:13: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say '&protocolController::action_LoginUsername'
- protocolController.cpp:14: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say '&protocolController::action_LoginPassword'
- protocolController.cpp:15: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say '&protocolController::action_RegisterUsername'
- protocolController.cpp:16: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say '&protocolController::action_RegisterPassword'
- protocolController.cpp:17: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say '&protocolController::action_RegisterEmail'
- $
复制代码 |
|