0

我试图让一个对话框 [import] 从另一个对话框 [baseline] 启动。我包含了所需的“.h”文件,但是我根本无法创建导入类的实例。我得到的错误是这样的:

Error   1   error C2146: syntax error : missing ';' before identifier 'iDlg'    h:\shaunak\projects\sar_ccd\sar_ccd\baseline.h  202 1   Sar_CCD

导致此 [baseline.h] 的代码行:

#include "Markup.h" 
#include<stdio.h>
#include<math.h>
#include "baseline_func.h"
#include "resource.h"
#include "Functions.h"
#include <stdlib.h>
#include "Sar_CCDDoc.h"
#include "Sar_CCDView.h"
#include <vector>
#include "MemAlloc.h"
#include "ReadFiles.h"
#include<vector>
#include<map>
#include "afxwin.h"
#include "import.h"
#include "Geocode.h"




**<SNIP: Taking out the irrelevant lines>**

     afx_msg void OnDestroy();
     virtual void PostNcDestroy();
     afx_msg void OnBnClickedNxtBase();
     CButton nextBaseline;


    import iDlg;               //doesnt work!
    CGeocoding cx;             //works!!!
};

但是,如果我像这样使用相同的 sysntax 创建另一个类 [Geocoding] 的实例,它可以正常工作:

#include "Geocoding.h"
CGeocoding cx;

请帮我弄清楚原因。

完整代码:

基线.h:http: //freetexthost.com/on06wref6c import.h:http ://freetexthost.com/x4e4dkwrve

4

2 回答 2

1

在 Visual Studio 中,有一个关键字 import 或 #import 用于导入 COM DLL,也用于其他事情。我猜您在那里遇到了名称冲突。

为了绕过它,将您的类导入放在namespace

import.h

namespace myimport
{
  class import : public CDialog { 
  ...
  };
};

import.cpp

namespace myimport
{
  ...
};

那么当你使用它时

myimport::import iDlg;

这应该可以解决问题,尽管将其重命名为“import”以外的其他名称将是更好的方法。

于 2012-07-16T10:57:22.570 回答
0

import不是 C++ 中的关键字或类型。因此,您会收到语法错误,因为编译器无法识别import.

要创建另一个类的实例,您必须正确声明它,例如:

class baseline : public CDialog
{
    // ...

    CDialog *iDlg;  // Pointer to imported dialog
};

请记住初始化指向实际对话框的指针。

于 2012-07-16T10:20:51.473 回答