zoukankan      html  css  js  c++  java
  • 做MFC的时候引用了头文件但VC还是报missing storage-class or type specifiers

    我在客户端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
    整了好久就是不知道哪边有问题,

     1 // 客户端Dlg.h : header file
     2 //
     3 
     4 #if !defined(AFX_DLG_H__65522289_1F04_4B8E_AA6C_FDFD80E5CF71__INCLUDED_)
     5 #define AFX_DLG_H__65522289_1F04_4B8E_AA6C_FDFD80E5CF71__INCLUDED_
     6 
     7 #if _MSC_VER > 1000
     8 #pragma once
     9 #endif // _MSC_VER > 1000
    10 
    11 #include "AddrDlg.h"
    12 #include "ClientSocket.h"
    13 
    14 /////////////////////////////////////////////////////////////////////////////
    15 // CMyDlg dialog
    16 
    17 class CMyDlg : public CDialog
    18 {
    19 // Construction
    20 public:
    21     CMyDlg(CWnd* pParent = NULL);   // standard constructor
    22     char m_ServerAddr[256];         //IP地址
    23     
    24 // Dialog Data
    25     //{{AFX_DATA(CMyDlg)
    26     enum { IDD = IDD_MY_DIALOG };
    27     CListBox    m_MsgR;
    28     CEdit   m_MsgS;
    29     //}}AFX_DATA
    30 
    31     // ClassWizard generated virtual function overrides
    32     //{{AFX_VIRTUAL(CMyDlg)
    33     protected:
    34     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    35     //}}AFX_VIRTUAL
    36 
    37 // Implementation
    38 protected:
    39     HICON m_hIcon;
    40     int TryCount;                                       //最大连接次数
    41     CClientSocket m_clientSocket;
    42     UINT m_Port;                                        //端口号
    43     // Generated message map functions
    44     //{{AFX_MSG(CMyDlg)
    45     virtual BOOL OnInitDialog();
    46     afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    47     afx_msg void OnPaint();
    48     afx_msg HCURSOR OnQueryDragIcon();
    49     afx_msg void OnConnect();
    50     afx_msg void OnSend();
    51     afx_msg void OnClose();
    52     afx_msg void OnTimer(UINT nIDEvent);
    53     //}}AFX_MSG
    54     DECLARE_MESSAGE_MAP()
    55 };
    56 
    57 //{{AFX_INSERT_LOCATION}}
    58 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
    59 
    60 #endif // !defined(AFX_DLG_H__65522289_1F04_4B8E_AA6C_FDFD80E5CF71__INCLUDED_)

    在你的对话框声明前面添加:

    1 class CClientSocket;

    强制声明一下就 ok 了。
    这个是 C++ 嵌套类定义检查的问题,在 include 之后要声明一下才能使用这个类。

    我找到问题的根源了,我在客户端clg.h头文件中引用了头文件“ClientSocket.h”,又在ClientSocket.h中include了客户端clg.h。

    还有,对于你的这种两个头文件互相包含的方式,是不好的做法,应该想办法改掉。

    文章来源:http://www.dewen.org/q/9850

  • 相关阅读:
    centos使用--排查服务是否可用
    centos使用--开机启动
    centos使用--防火墙
    centos使用--软件启动关闭等操作的命令
    centos使用--supervisor使用
    centos使用--centos7.3配置LNMP
    centos使用--vim配置和推荐插件使用
    centos使用--ssh登陆
    HTML5 sessionStorage会话存储
    localStorage使用
  • 原文地址:https://www.cnblogs.com/qiernonstop/p/3717808.html
Copyright © 2011-2022 走看看