我自己写了个GetLocalNC.h的类 
在视图中include了 
#include "ncm/GetLocalNC.h"。 然后我还在我新建的dialog.cpp中包含GetLocalNC.h和视图类。 
然后声明GetNetAllHostInfo getncinfo; 
却提示有3个错误 
--------------------Configuration: NMC - Win32 Debug-------------------- 
Compiling... 
ScanHostInfo.cpp 
J:\Recent Project\2008\NetPro\NMC\NMC\ScanHostInfo.cpp(99) : error C2065: 'GetNetAllHostInfo' : undeclared identifier 
J:\Recent Project\2008\NetPro\NMC\NMC\ScanHostInfo.cpp(99) : error C2146: syntax error : missing ';' before identifier 'getncinfo' 
J:\Recent Project\2008\NetPro\NMC\NMC\ScanHostInfo.cpp(99) : error C2065: 'getncinfo' : undeclared identifier 
Error executing cl.exe. 
Creating browse info file... NMC.exe - 3 error(s), 0 warning(s) 
请问如何解决 
谢谢了...

解决方案 »

  1.   

    有可能是头文件相互包含造成的,你检查一下你的GetNetAllHostInfo中有没有使用到view类或是其它有可能相互包含的类声明。如果是上述问题的话,你在相应的文件上加上一个类声明就可以了。
    如:
    class GetNetAllHostInfo;
      

  2.   

    #include "ncm/GetLocalNC.h"。  改成ncm\xxxxx.h
      

  3.   

    我也感觉是头文件包含问题...因为我在view里面包含了GetLocalNC.h的文件
    然后我还想在dlg中包含...可是如果不在dlg中包含
    那我怎末调用到GetLocalNC.h的函数呢?
    用了class GetNetAllHostInfo;
    还是出错:
    --------------------Configuration: NMC - Win32 Debug--------------------
    Compiling...
    ScanHostInfo.cpp
    J:\Recent Project\2008\NetPro\NMC\NMC\ScanHostInfo.cpp(90) : error C2065: 'GetNetAllHostInfo' : undeclared identifier
    J:\Recent Project\2008\NetPro\NMC\NMC\ScanHostInfo.cpp(90) : error C2146: syntax error : missing ';' before identifier 'gnd'
    J:\Recent Project\2008\NetPro\NMC\NMC\ScanHostInfo.cpp(90) : error C2065: 'gnd' : undeclared identifier
    Error executing cl.exe.
    Creating browse info file...NMC.exe - 3 error(s), 0 warning(s)
      

  4.   

    // ScanHostInfo.cpp : implementation file
    //
    #pragma comment(lib,"wpcap.lib")
    #pragma   comment(lib,"ws2_32")   
    #pragma   comment(lib,"packet")
    #include "stdafx.h"
    #include "NMC.h"
    //#include "NMCDoc.h"
    //#include "NMCView.h"#pragma warning(disable:4786)
    #include <vector>#include "ScanHostInfo.h"
    /*#include "ncm/GetLocalNC.h"*/
    class GetNetAllHostInfo;
    //using namespace std;#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CScanHostInfo dialogCScanHostInfo::CScanHostInfo(CWnd* pParent /*=NULL*/)
    : CDialog(CScanHostInfo::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CScanHostInfo)
    m_endip = _T("");
    m_startip = _T("");
    //}}AFX_DATA_INIT
    }
    void CScanHostInfo::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CScanHostInfo)
    DDX_Control(pDX, IDC_LAN_HOST_LIST, m_hostinfoctrl);
    DDX_Text(pDX, IDC_END_IP_EDIT, m_endip);
    DDX_Text(pDX, IDC_START_IP_EDIT, m_startip);
    //}}AFX_DATA_MAP
    }
    BEGIN_MESSAGE_MAP(CScanHostInfo, CDialog)
    //{{AFX_MSG_MAP(CScanHostInfo)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CScanHostInfo message handlersvoid CScanHostInfo::OnCancel() 
    { CDialog::OnCancel();
    }void CScanHostInfo::OnOK() 
    {
    // TODO: Add extra validation here //CDialog::OnOK();
    m_hostinfoctrl.DeleteAllItems();
    GetNetAllHostInfo dd;
    //  CONST char* aa;
    //  CString bb;
    //  aa="192.168.1.88";
    //  bb=(gnd.GetLocalHostMAC(aa)).c_str();

    // GetNetAllHostInfo getncinfo;

    UpdateData(TRUE);
    UpdateData(FALSE);
    if (m_startip!=""&&m_endip!="")
    {

    m_hostinfoctrl.InsertItem(0,"192.168.1.88");
    m_hostinfoctrl.SetItemText(0,1,"DMS");
    m_hostinfoctrl.SetItemText(0,2,"0000"); }else{
    MessageBox("请输入要扫描开始网段和结束网段!",0,0);
    }
    }BOOL CScanHostInfo::OnInitDialog() 
    {
    CDialog::OnInitDialog();

    // TODO: Add extra initialization here

    // m_hostinfoctrl.InsertColumn(0,"学号",LVCFMT_CENTER,100,-1); m_hostinfoctrl.DeleteColumn(0);
    m_hostinfoctrl.InsertColumn(0,"IP 地址",LVCFMT_CENTER,200,-1);
    m_hostinfoctrl.DeleteColumn(1);
    m_hostinfoctrl.InsertColumn(1,"主机名",LVCFMT_CENTER,200);
    m_hostinfoctrl.DeleteColumn(2);
    m_hostinfoctrl.InsertColumn(2,"MAC 地址",LVCFMT_CENTER,200);
    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
    }
    ++++++++++++++++++++++++++++++++++++--------------------Configuration: NMC - Win32 Debug--------------------
    Compiling...
    ScanHostInfo.cpp
    J:\Recent Project\2008\NetPro\NMC\NMC\ScanHostInfo.cpp(91) : error C2079: 'dd' uses undefined class 'GetNetAllHostInfo'
    Error executing cl.exe.
    Creating browse info file...NMC.exe - 1 error(s), 0 warning(s)
      

  5.   

    一加#include "ncm/GetLocalNC.h"
    就出现71个错误
    --------------------Configuration: NMC - Win32 Debug--------------------
    Compiling...
    ScanHostInfo.cpp
    d:\program files\microsoft sdk\include\winsock2.h(109) : error C2011: 'fd_set' : 'struct' type redefinition
    d:\program files\microsoft sdk\include\winsock2.h(144) : warning C4005: 'FD_SET' : macro redefinition
            d:\program files\microsoft sdk\include\winsock.h(88) : see previous definition of 'FD_SET'
    d:\program files\microsoft sdk\include\winsock2.h(153) : error C2011: 'timeval' : 'struct' type redefinition
    d:\program files\microsoft sdk\include\winsock2.h(209) : error C2011: 'hostent' : 'struct' type redefinition
    d:\program files\microsoft sdk\include\winsock2.h(222) : error C2011: 'netent' : 'struct' type redefinition
    d:\program files\microsoft sdk\include\winsock2.h(229) : error C2011: 'servent' : 'struct' type redefinition
    ScanHostInfo.obj - 71 error(s), 19 warning(s)
      

  6.   

    超前引用了?看看http://www.vckbase.com/bbs/prime/viewprime.asp?id=431
      

  7.   

    1.ScanHostInfo.cpp这个对话框类还是要
    #include "ncm/GetLocalNC.h"
    你只有一个类声明是编不过的。2.还有你的类class GetNetAllHostInfo中有没有成员变量是NMCView类型的?有的话你应该在
    GetNetAllHostInfo类的头文件上加上class NMCView;而不是在现在这个位置加了class GetNetAllHostInfo; 3.至于redefinition的错误应该比较好解决,你仔细看vc的错误提示就能找到是在哪里重定义了。
      

  8.   

    Include自己的头文件一般放在Dialog.h里比较合适
      

  9.   

    应该不是重复包含的问题,因为用AppWizard生成的类框架,都有防止重复包含的处理。
    确定一下你定义的类的类名称是GetNetAllHostInfo还是CGetNetAllHostInfo??
      

  10.   

    #include "ncm/GetLocalNC.h" 
    类也声明了
    还是编不过的...
      

  11.   

    #include "ncm/GetLocalNC.h"
    #include "stdafx.h"
    #include "NMC.h"
    //#include "NMCDoc.h"
    //#include "NMCView.h"//#pragma warning(disable:4786)
    //#include <vector>#include "ScanHostInfo.h"//#include "ncm/GetLocalNC.h"class GetNetAllHostInfo;以上是include 和 声明....
    然后在
    CScanHostInfo::OnOK()函数中声明  GetNetAllHostInfo gg;之后报错:--------------------Configuration: NMC - Win32 Debug--------------------
    Compiling...
    ScanHostInfo.cpp
    J:\Recent Project\2008\NetPro\NMC\NMC\ScanHostInfo.cpp(104) : error C2079: 'gg' uses undefined class 'GetNetAllHostInfo'
    Error executing cl.exe.NMC.exe - 1 error(s), 0 warning(s)
      

  12.   

    这是我GetNetAllHostInfo.h里面的内容
    #pragma warning(disable:4786)
    #pragma comment(lib,"wpcap.lib")
    #pragma   comment(lib,"ws2_32")   
    #pragma   comment(lib,"packet")  
    #ifndef WIN32
    #include <sys/socket.h>
    #include <netinet/in.h>
    #else
    #include <winsock.h>
    #endif
    #include <WinSock2.h>
    #include <iostream>
    #include <pcap.h>
    #include <remote-ext.h>
    #include <vector>
    #include <IPHlpApi.h>
    #include <string>using namespace  std;
    class GetNetAllHostInfo{........}