做MFC的时候引用了头文件但VC还是报missing storage-class or type specifiers
2014-05-08 22:26
495 查看
我在客户端clg.h头文件中引用了头文件“ClientSocket.h”,然后在客户端clg.h中的类中声明了类CClientSocket的对象,可是编译报错:
d:\vc++\客户端\客户端dlg.h(44) : error C2146: syntax error : missing ';' before identifier 'm_clientSocket'
d:\vc++\客户端\客户端dlg.h(44) : error C2501: 'CClientSocket' : missing storage-class or type specifiers
d:\vc++\客户端\客户端dlg.h(44) : error C2501: 'm_clientSocket' : missing storage-class or type specifiers
整了好久就是不知道哪边有问题,
在你的对话框声明前面添加:
强制声明一下就 ok 了。
这个是 C++ 嵌套类定义检查的问题,在 include 之后要声明一下才能使用这个类。
我找到问题的根源了,我在客户端clg.h头文件中引用了头文件“ClientSocket.h”,又在ClientSocket.h中include了客户端clg.h。
还有,对于你的这种两个头文件互相包含的方式,是不好的做法,应该想办法改掉。
文章来源:http://www.dewen.org/q/9850
d:\vc++\客户端\客户端dlg.h(44) : error C2146: syntax error : missing ';' before identifier 'm_clientSocket'
d:\vc++\客户端\客户端dlg.h(44) : error C2501: 'CClientSocket' : missing storage-class or type specifiers
d:\vc++\客户端\客户端dlg.h(44) : error C2501: 'm_clientSocket' : missing storage-class or type specifiers
整了好久就是不知道哪边有问题,
// 客户端Dlg.h : header file // #if !defined(AFX_DLG_H__65522289_1F04_4B8E_AA6C_FDFD80E5CF71__INCLUDED_) #define AFX_DLG_H__65522289_1F04_4B8E_AA6C_FDFD80E5CF71__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include "AddrDlg.h" #include "ClientSocket.h" ///////////////////////////////////////////////////////////////////////////// // CMyDlg dialog class CMyDlg : public CDialog { // Construction public: CMyDlg(CWnd* pParent = NULL); // standard constructor char m_ServerAddr[256]; //IP地址 // Dialog Data //{{AFX_DATA(CMyDlg) enum { IDD = IDD_MY_DIALOG }; CListBox m_MsgR; CEdit m_MsgS; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CMyDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: HICON m_hIcon; int TryCount; //最大连接次数 CClientSocket m_clientSocket; UINT m_Port; //端口号 // Generated message map functions //{{AFX_MSG(CMyDlg) virtual BOOL OnInitDialog(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); afx_msg void OnConnect(); afx_msg void OnSend(); afx_msg void OnClose(); afx_msg void OnTimer(UINT nIDEvent); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_DLG_H__65522289_1F04_4B8E_AA6C_FDFD80E5CF71__INCLUDED_)
在你的对话框声明前面添加:
class CClientSocket;
强制声明一下就 ok 了。
这个是 C++ 嵌套类定义检查的问题,在 include 之后要声明一下才能使用这个类。
我找到问题的根源了,我在客户端clg.h头文件中引用了头文件“ClientSocket.h”,又在ClientSocket.h中include了客户端clg.h。
还有,对于你的这种两个头文件互相包含的方式,是不好的做法,应该想办法改掉。
文章来源:http://www.dewen.org/q/9850
相关文章推荐
- [VC++]missing storage-class or type specifiers
- 'HDEVNOTIFY' : missing storage-class or type specifiers
- Vc error C2629: unexpected 'class***或error C2501: missing storage-class or type specifiers
- error C2501: 'string' : missing storage-class or type specifiers
- 'IplImage' : missing storage-class or type specifiers
- 'IplImage' : missing storage-class or type specifiers
- 头文件交叉定义出现--GetDocument missing storage-class or type specifiers错误的解决方法
- 'HDEVNOTIFY' : missing storage-class or type specifiers
- 有关error C2501: 'WINGDIAPI' : missing storage-class or type specifiers的错误
- missing storage-class or type specifiers的解决方法
- error C2501: 'GetDocument' : missing storage-class or type specifiers 问题的处理
- error C2501: 'AUX_RGBImageRec' : missing storage-class or type specifiers
- unexpected 'class***或error C2501: missing storage-class or type specifiers 错误解决办法
- error C2501: '_Application' : missing storage-class or type specifiers
- '_ConnectionPtr' : missing storage-class or type specifiers
- '_ConnectionPtr' : missing storage-class or type specifiers
- missing storage-class or type specifiers的原因及解决办法
- 关于dsound.h的问题error C2501: 'DWORD_PTR' : missing storage-class or type specifiers
- GetDocument missing storage-class or type specifiers的解决方法
- C++ 问题 unknown type name 'class' c中头文件在cpp文件中引用和.h文件引用的思考