天天看點

error: call to non-static member function without an object argument

error: call to non-static member function without an object argument

1.在c++中,如果一個類中有個靜态方法,那麼這個靜态方法中調用的也是靜态方法

2.在c++中,一個類的普通函數,既可以調用非靜态方法,也可以調用靜态方法

例如:

DriverOfNet類中有個靜态函數  netCallBackData

還有一個非靜态函數 ConvertToHex

static void __stdcall netCallBackData(int cardId, char* pData, int length, void *user);

std::string ConvetToHex(char* data, int len);

如果想要在 netCallBackData函數中調用ConvetToHex函數,就會報錯,所有要把ConvetToHex函數改成靜态函數

class DriverOfNet: public INet, public IEbtNet
{

public:
    DriverOfNet();
    ~DriverOfNet();




    /**
     * @brief 向下位機下發控制指令
     * @param cardid  卡編号
     * @param pMsg  指令資訊
     * @param iLen  指令長度
     * @return
     */

    int SendMsg(char* msg, int len);
    int Connect(const char* ip, int port);


    int RegisterRespondCallback(NetCmdCallback call, void* ptr);
    int RegisterDataCallback(NetDataCallback call, void* ptr );
    int RegisterStatusCallBack(StatusCallback call, void* ptr);

private:

    static void __stdcall netCallBackData(int cardId, char* pData, int length, void *user);
    static void __stdcall netStatusCallBack(NET_CONNENT_STATE status, void *userData);
    static void __stdcall callbackCmdRsp(char* pData, int length, void *user);
    static void __stdcall callbackApiStatus(int cardId, char*);
    static void __stdcall apiPrintlog(char*);
    static void __stdcall callbackNewDevIp(char* newDevIp);
    static void __stdcall updateFpgaCompleteCallback(int cardId, int status);

    static std::string ConvetToHex(char* data, int len);

private:

    int card_id;
    std::list<CARD_S> m_cardList;
    void* dataPtr ;
    NetDataCallback OnSendNetData;
    void* cmdPtr;
    NetCmdCallback OnSendCmdData;
    void* statusPtr;
    StatusCallback OnSendStatus;

    std::map<int, NetStatus> m_card_status;

    EBIT_DEVICE_S* dev;



};

#endif // DRIVEROFNET_H      

繼續閱讀