C++ C++;类静态成员函数调用错误
我用visualstudio写了一个项目。在该项目中,我构建了一个名为csimapplicancedlg的类,该类有两个成员:C++ C++;类静态成员函数调用错误,c++,visual-studio,mfc,static-methods,static-functions,C++,Visual Studio,Mfc,Static Methods,Static Functions,我用visualstudio写了一个项目。在该项目中,我构建了一个名为csimapplicancedlg的类,该类有两个成员: static UINT RecvDataFrame(LPVOID pParam)和CSerialPort m_Port class CSimApplianceDlg : public CDialog { // Construction public: CSimApplianceDlg(CWnd* pParent = NULL); // standard construc
static UINT RecvDataFrame(LPVOID pParam)
和CSerialPort m_Port
class CSimApplianceDlg : public CDialog
{
// Construction
public:
CSimApplianceDlg(CWnd* pParent = NULL); // standard constructor
// Implementation
protected:
HICON m_hIcon;
// Added for Serial Port operation
static UINT RecvDataFrame(LPVOID pParam); // Process received data
......
private:
......
unsigned char m_SendData[MAX_LEN]; // Data to be sent
int len; // the length of data to be sent
public:
CSerialPort m_Port; // CSerialPort Object
......
CSerialPort
有一个公共成员函数writeport
通过串口发送数据
public:
void WriteToPort(char* string);
void WriteToPort(char* string,int n);
void WriteToPort(LPCTSTR string);
void WriteToPort(LPCTSTR string,int n);
我打电话
m_Port.writeport(m_SendData,len)代码>
在UINT csimapplicancedlg::RecvDataFrame(LPVOID pParam)中。然而,在建设项目的过程中,就在电话那头,我得到了
1> e:\mysourcecode\smarthome\simappliance\simappliancedlg.cpp(557)
:错误C2228:“.WritePort”左侧必须具有类/结构/联合
1> e:\mysourcecode\smarthome\simappliance\simappliancedlg.cpp(557):错误C2597:非法引用非静态成员“CSIMApplicancedLG::m_SendData”
1> e:\mysourcecode\smarthome\simappliance\simappliancedlg.cpp(557):错误C2597:非法引用非静态成员“CSimApplianceDlg::len”
我如何处理这些错误?调用哪个writeport
,因为
我不熟悉LPCTSTR
静态UINT RecvDataFrame(LPVOID pParam)功能是静态的。这意味着您可以在不实例化对象csimapplicancedlg的情况下调用它。换句话说,您可以从任何地方调用csimapplicancedlg::RecvDataFrame(),这通常是回调函数的情况。
这意味着在该函数中,您无法访问成员变量(m_端口)。
如前所述,我们没有足够的信息提供帮助,但传递的pParam可能有一个指向该对象的指针。。。或者,如果它是应用程序中的唯一窗口,您可以尝试AfxGetMainWnd()。
LPCTSTR简单地定义为const TCHAR*,其中TCHAR是char或wchar\u t
如果您使用的是ANSI或Unicode。祝你好运 您忘记显示发生这些错误的代码。您可能未能创建CSerialPort
类的实例。正如Michael所说,除非我们能看到实际的代码,否则我们无法确定。请在调用“m_Port.writeport(m_SendData,len)”时使用.errors applears更新您的问题