class.h for child window

COverlayDlg will be a modeless child dialog in MFC. I'm trying to add the ability to send messages to the parent dialog window TableDlg. What could be wrong here ? Thanks !
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#pragma once

#include "resource.h"
#include "TableDlg.h"

// COverlayDlg dialog

class COverlayDlg : public CDialog
{
	DECLARE_DYNAMIC(COverlayDlg)

public:
	COverlayDlg::COverlayDlg(CTableDlg *parent);   // error C2061 !!!!
	virtual ~COverlayDlg();

// Dialog Data
	enum { IDD = IDD_OVERLAY };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

	DECLARE_MESSAGE_MAP()
public:
	TableDlg *__parent;               //error C4430 !!!
	afx_msg void OnBnClickedOk();
};


error C2061: syntax error : identifier 'CTableDlg'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Last edited on
I think we have to see the "TableDlg.h" file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//"TableDlg.h"

class CTableDlg : public CDialog
{
// Construction
public:
	CTableDlg (CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_TABLE_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	CStatic m_hInfo;
	CString m_sInfo;
	CStatic m_hRuntime;
	CString m_sRuntime;
	afx_msg void OnBnClickedStart();
	CButton m_btnStart;

protected:
//	afx_msg LRESULT OnAsyncMsg(WPARAM wParam, LPARAM lParam);
public:
//	virtual BOOL PreTranslateMessage(MSG* pMsg);
//	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	CStatic m_hWindowSize;
	CString m_sWindowSize;
};
From
TableDlg *__parent;
To
CTableDlg *__parent;
Thanks !
I must have miscopied. I do have CTableDlg *__parent; in my source...
Try writing
class CTableDlg;
before
class COverlayDlg : /*...*/
That did it thank you !
The reason why the problem happened was probably this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// TableDlg.h
#ifndef TABLEDLG_H
#define TABLEDLG_H
#include "OverlayDlg.h"
class CTableDlg {
/* ... */
};

// OverlayDlg.h
#ifndef OVERLAYDLG_H
#define OVERLAYDLG_H
#include "TableDlg.h"
class COverlayDlg {
/* ... */
};

// TableDlg.cpp
#include "TableDlg.h"

/* ... */

// OverlayDlg.cpp
#include "OverlayDlg.h"

/* ... */


Now, the .cpp files are just empty but the includes (They are required for this to happen tho, despite that not being the reason).

Think about the compiling of tabledlg.cpp:

1. Include TableDlg.h
TABLEDLG_H gets defined
2. Include OverlayDlg (from TableDlg.h)
OVERLAYDLG_H gets defined
3. Re-include TableDlg.h
TABLEDLG_H is already defined, file is skipped.
4. Declare COverlayDlg
All right until now
5. Try to use CTableDlg in COverlayDlg
CTableDlg is not declared yet! This is the error.

To avoid this, pre-declare the classes before the class they're used into.

1
2
3
4
5
6
7
8
9
10
11
// OverlayDlg.h
class CTableDlg;
class COverlayDlg {
    CTableDlg* pTable;
};

// TableDlg.h
class COverlayDlg;
class CTableDlg {
    COverlayDlg* pOverlay;
};


Now, you already (hopefully) have the solution, but this is why it happened, in case you wondered.

Another way is to move includes before the header guards, but I can't guarantee it works.
Last edited on
Topic archived. No new replies allowed.