Dears,I have a really big problem.I have two classes. ClassA and ClassB. Both in separate CPP files and both have H header files.ClassA uses ClassB and ClassB uses ClassA. So I have included ClassA.h in ClassB.h and the same
way included B in A.I use MSVC++ 6.0.The compiler cannot find definition or declaration of both classes. My friend told me that this
thing should help:ClassA.h:
extern class ClassBClassB.h:
extern class ClassABut it didn`t help. Compiler warns me something about left side in extern and that it is ignoring it.I really need separate files so I made a test without WX and IT WORKED (no warnings).I created the project with the wxWizard. Maybe there is some mistake in makefile or something.CAN YOU HELP ME, PLEASE?Thank you much!
way included B in A.I use MSVC++ 6.0.The compiler cannot find definition or declaration of both classes. My friend told me that this
thing should help:ClassA.h:
extern class ClassBClassB.h:
extern class ClassABut it didn`t help. Compiler warns me something about left side in extern and that it is ignoring it.I really need separate files so I made a test without WX and IT WORKED (no warnings).I created the project with the wxWizard. Maybe there is some mistake in makefile or something.CAN YOU HELP ME, PLEASE?Thank you much!
这样会是include循环
用其他方法吧 或者把两个类放到一对.H .CPP文件中可以解决
ClassA.h:
extern class ClassBClassB.h:
extern class ClassA
的前提下,再在你的每个头文件的最前面加一个
#pragma once
即可,但要求VC6.0及其以上版本
extern class ClassB -> class ClassB;
extern class ClassA -> class ClassA;
如果编译时出错,一个简单的方法(不过不是很好):
// A.h
#pragma once // 在B.h的最开头
#include "B.h"
class B;
class A
{
};// B.h
#pragma once // 在B.h的最开头
#include "A.h"
class A;
class B
{
};
lop5712的方法是可行的,但对于
/////////////////////////////////////////////////////////////////////////////
// CSelFontDlg dialog
class CSelFontDlg : public CDialog
{
// Construction
public:
CSelFontDlg(CWnd* pParent = NULL); // standard constructor// Dialog Data
//{{AFX_DATA(CSelFontDlg)
// NOTE: the ClassWizard will add data members here
enum { IDD = IDD_SEl_FONTTYPE };
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSelFontDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected: // Generated message map functions
//{{AFX_MSG(CSelFontDlg)
virtual BOOL OnInitDialog();
afx_msg void OnRADIODualLines() ;
afx_msg void OnRADIOSingleLine() ;
afx_msg void OnRADIOExtraWide() ;
// NOTE: the ClassWizard will add member functions here
//}}AFX_MSG DECLARE_MESSAGE_MAP()};CSelFontDlg::CSelFontDlg(CWnd* pParent )
: CDialog(CSelFontDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSelLptDlg)
// NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT
}void CSelFontDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSelFontDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CSelFontDlg, CDialog)
//{{AFX_MSG_MAP(CSelFontDlg)
// NOTE: the ClassWizard will add message map macros here
ON_BN_CLICKED(IDC_RADIO_DualLines, OnRADIODualLines)
ON_BN_CLICKED(IDC_RADIO_SingleLine, OnRADIOSingleLine)
ON_BN_CLICKED(IDC_RADIO_ExtraWide, OnRADIOExtraWide)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()BOOL CSelFontDlg::OnInitDialog()
{
CDialog::OnInitDialog(); return true;
}
void CSelFontDlg::OnRADIODualLines()
{
// TODO: Add your control notification handler code here
//Sel3Font=0;
//buttonsimple->SetCheck(1); }void CSelFontDlg::OnRADIOSingleLine()
{
// TODO: Add your control notification handler code here
//Sel3Font=1;
//buttontraditional->SetCheck(1);
}void CSelFontDlg::OnRADIOExtraWide()
{
// TODO: Add your control notification handler code here
//Sel3Font=1;
//buttontraditional->SetCheck(1);
}这样一个类如何引用,我不知道该怎么做? 如何在另一个文件引用
CSelFontDlg selfontdlg;
selfontdlg.DoModal();比如 DEMOVIEW.CPP(SDI)