BeerFizz
Technical User
- Jan 23, 2004
- 28
Hi,
Sorry for the length post, but I thought I should include as much info as possible.
I am just starting to use MS Visual C++ 6.0 and OOP and I’m having a problem passing/getting the handle to one class from another. I have written a simple Dialog Class test program to show my issue.
Test2App
|
|
creates 2 dialogs
Tab1 and Tab2
Tab1 attempts to access a public member in another class “test”
Portions of the code are as follows
Test2App has the following code which creates a property sheet with two tab pages:
CPropertySheet dlgPropertySheet;
DialogTab1 Tab1Page;
Dialog2Tab2 Tab2Page;
dlgPropertySheet.AddPage(&Tab1Page);
dlgPropertySheet.AddPage(&Tab2Page);
Tab1Page.m_Tab1Edit1 = "This is a test";
Tab1Page.m_CheckBoxOne = TRUE;
if (dlgPropertySheet.DoModal() == IDOK)
{
str1 = Tab1Page.m_Tab1Edit1;
str2 = Tab2Page.m_Tab2Edit1;
Tab1Page.SetModified();
}
Dialog Tab1 has the following code:
BOOL DialogTab1::OnInitDialog()
{
CPropertyPage::OnInitDialog();
// TODO: Add extra initialization here
int n = TestRef.AddTwoNum( 5, 8);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
Class Test has the following code:
class Test : public CDialog
{
// Construction
public:
Test(CWnd* pParent = NULL); // standard constructor
int AddTwoNum(int n, int m) {
return n+m;
}
…
To allow DialogTab1 to access the public member AddTwoNum, I tried to pass the handle of test. The following are excerpts from the code: (hopefully I’m being sufficiently clear?)
In test .h:
#include "DialogTab1.h"
In test.cpp:
Test::Test(CWnd* pParent /*=NULL*/)
: CDialog(Test::IDD, pParent),
DialogTab1( *this)
{
//{{AFX_DATA_INIT(Test)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
In DialogTab1.h:
class Test; // Forward Declaration
/////////////////////////////////////////////////////////////////////////////
// DialogTab1 dialog
class DialogTab1 : public CPropertyPage
{
DECLARE_DYNCREATE(DialogTab1)
// Construction
public:
DialogTab1(Test &);
~DialogTab1();
…
…
private:
Test &TestRef;
In DialogTab1.cpp:
/////////////////////////////////////////////////////////////////////////////
// DialogTab1 property page
IMPLEMENT_DYNCREATE(DialogTab1, CPropertyPage)
DialogTab1:ialogTab1(Test &TestHandle) : CPropertyPage(DialogTab1::IDD),
TestRef( TestHandle)
{
//{{AFX_DATA_INIT(DialogTab1)
m_Tab1Edit1 = _T(""
m_CheckBoxOne = FALSE;
//}}AFX_DATA_INIT
}
DialogTab1::~DialogTab1()
{
…
I get the following compiler error:
Compiling...
DialogTab1.cpp
C:\Awork\Data Reply\Sample C\test2\DialogTab1.cpp(19) : error C2512: 'DialogTab1' : no appropriate default constructor available
(this is against this code:
/////////////////////////////////////////////////////////////////////////////
// DialogTab1 property page
IMPLEMENT_DYNCREATE(DialogTab1, CPropertyPage) <<<<<<< error on this line
DialogTab1:ialogTab1(Test &TestHandle) : CPropertyPage(DialogTab1::IDD),
TestRef( TestHandle)
{
)
Test.cpp
C:\Awork\Data Reply\Sample C\Test2\Test.cpp(20) : warning C4355: 'this' : used in base member initializer list
(This is against this code:
Test::Test(CWnd* pParent /*=NULL*/)
: CDialog(Test::IDD, pParent),
DialogTab1( *this) <<<<<<<<< error on this line
{
)
C:\Awork\Data Reply\Sample C\Test2\Test.cpp(21) : error C2614: 'Test' : illegal member initialization: 'DialogTab1' is not a base or member
(This is against this code:
Test::Test(CWnd* pParent /*=NULL*/)
: CDialog(Test::IDD, pParent),
DialogTab1( *this)
{ <<<<<<<<< error on this line
)
Generating Code...
Compiling...
test2Dlg.cpp
C:\Awork\Data Reply\Sample C\test2\test2Dlg.cpp(126) : error C2512: 'DialogTab1' : no appropriate default constructor available
Generating Code...
‘
If this is not sufficient to go on, please pm me and I’ll send you a zip of the files.
If anyone can help, I would appreciate it.
Thanks
Sorry for the length post, but I thought I should include as much info as possible.
I am just starting to use MS Visual C++ 6.0 and OOP and I’m having a problem passing/getting the handle to one class from another. I have written a simple Dialog Class test program to show my issue.
Test2App
|
|
creates 2 dialogs
Tab1 and Tab2
Tab1 attempts to access a public member in another class “test”
Portions of the code are as follows
Test2App has the following code which creates a property sheet with two tab pages:
CPropertySheet dlgPropertySheet;
DialogTab1 Tab1Page;
Dialog2Tab2 Tab2Page;
dlgPropertySheet.AddPage(&Tab1Page);
dlgPropertySheet.AddPage(&Tab2Page);
Tab1Page.m_Tab1Edit1 = "This is a test";
Tab1Page.m_CheckBoxOne = TRUE;
if (dlgPropertySheet.DoModal() == IDOK)
{
str1 = Tab1Page.m_Tab1Edit1;
str2 = Tab2Page.m_Tab2Edit1;
Tab1Page.SetModified();
}
Dialog Tab1 has the following code:
BOOL DialogTab1::OnInitDialog()
{
CPropertyPage::OnInitDialog();
// TODO: Add extra initialization here
int n = TestRef.AddTwoNum( 5, 8);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
Class Test has the following code:
class Test : public CDialog
{
// Construction
public:
Test(CWnd* pParent = NULL); // standard constructor
int AddTwoNum(int n, int m) {
return n+m;
}
…
To allow DialogTab1 to access the public member AddTwoNum, I tried to pass the handle of test. The following are excerpts from the code: (hopefully I’m being sufficiently clear?)
In test .h:
#include "DialogTab1.h"
In test.cpp:
Test::Test(CWnd* pParent /*=NULL*/)
: CDialog(Test::IDD, pParent),
DialogTab1( *this)
{
//{{AFX_DATA_INIT(Test)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
In DialogTab1.h:
class Test; // Forward Declaration
/////////////////////////////////////////////////////////////////////////////
// DialogTab1 dialog
class DialogTab1 : public CPropertyPage
{
DECLARE_DYNCREATE(DialogTab1)
// Construction
public:
DialogTab1(Test &);
~DialogTab1();
…
…
private:
Test &TestRef;
In DialogTab1.cpp:
/////////////////////////////////////////////////////////////////////////////
// DialogTab1 property page
IMPLEMENT_DYNCREATE(DialogTab1, CPropertyPage)
DialogTab1:ialogTab1(Test &TestHandle) : CPropertyPage(DialogTab1::IDD),
TestRef( TestHandle)
{
//{{AFX_DATA_INIT(DialogTab1)
m_Tab1Edit1 = _T(""
m_CheckBoxOne = FALSE;
//}}AFX_DATA_INIT
}
DialogTab1::~DialogTab1()
{
…
I get the following compiler error:
Compiling...
DialogTab1.cpp
C:\Awork\Data Reply\Sample C\test2\DialogTab1.cpp(19) : error C2512: 'DialogTab1' : no appropriate default constructor available
(this is against this code:
/////////////////////////////////////////////////////////////////////////////
// DialogTab1 property page
IMPLEMENT_DYNCREATE(DialogTab1, CPropertyPage) <<<<<<< error on this line
DialogTab1:ialogTab1(Test &TestHandle) : CPropertyPage(DialogTab1::IDD),
TestRef( TestHandle)
{
)
Test.cpp
C:\Awork\Data Reply\Sample C\Test2\Test.cpp(20) : warning C4355: 'this' : used in base member initializer list
(This is against this code:
Test::Test(CWnd* pParent /*=NULL*/)
: CDialog(Test::IDD, pParent),
DialogTab1( *this) <<<<<<<<< error on this line
{
)
C:\Awork\Data Reply\Sample C\Test2\Test.cpp(21) : error C2614: 'Test' : illegal member initialization: 'DialogTab1' is not a base or member
(This is against this code:
Test::Test(CWnd* pParent /*=NULL*/)
: CDialog(Test::IDD, pParent),
DialogTab1( *this)
{ <<<<<<<<< error on this line
)
Generating Code...
Compiling...
test2Dlg.cpp
C:\Awork\Data Reply\Sample C\test2\test2Dlg.cpp(126) : error C2512: 'DialogTab1' : no appropriate default constructor available
Generating Code...
‘
If this is not sufficient to go on, please pm me and I’ll send you a zip of the files.
If anyone can help, I would appreciate it.
Thanks