Mike Mike - 1 month ago 6
C++ Question

error C2309: is not a member of CDialog

I have structure: PrintChooseDlg.h

#ifndef PRINTCHOOSEDLG_H
#define PRINTCHOOSEDLG_H
#include <string>
#pragma once
#endif


class CPrintChooseDlg : public CDialog
{


public:
int choosing;
/*afx_msg void OnPrinter1();
afx_msg void OnPrinter2();*/
CPrintChooseDlg(CWnd* pParent = NULL);
enum { IDD = IDD_PRINTBOX };


protected:
virtual void DoDataExchange(CDataExchange* pDX);
protected:
//afx_msg void OnPrinter1();
//afx_msg void OnPrinter2();
virtual void OnPrinter1();
virtual void OnPrinter2();
DECLARE_MESSAGE_MAP()
};


and PrintChooseDlg.cpp

// PrintChoose.cpp : implementation file
//

#include "stdafx.h"
#include "Tungsten.h"
#include "PrintChooseDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// PrintChoose

//IMPLEMENT_DYNAMIC(PrintChoose, CWnd)
CPrintChooseDlg::CPrintChooseDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPrintChooseDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CChooseLabelDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}


void CPrintChooseDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChooseLabelDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPrintChooseDlg, CDialog)
ON_BN_CLICKED(IDC_PRINTER1,OnPrinter1)
ON_BN_CLICKED(IDC_PRINTER2,OnPrinter2)
END_MESSAGE_MAP()



// PrintChoose message handlers

void CPrintChooseDlg::OnPrinter1()
{
choosing=0;
CDialog::OnPrinter1();
}
void CPrintChooseDlg::OnPrinter2()
{
choosing=1;
CDialog::OnPrinter2();
}


and in the main file where i am running from, i define the following headers:

#include "stdafx.h"
#include "Tungsten.h"
#include "TungstenDlg.h"
using namespace std;
#include<sstream>
#include <string>


The problem is i am always getting the following errors: error C2039: 'OnPrinter1': is not a member of 'CDialog'
error C2039: 'OnPrinter2': is not a member of 'CDialog'

What i tried is to add
#include <string>
at my header and make sure that the headers are not repeated, and defining Printer1 and Pronter 2 in the main file where i am running from, but i still get the same error. I appreciate your help. Thanks in Advance

Answer

To get the address of a member function, you need to use &CPrintChooseDlg::OnPrinter1.

Really old VC++, like VC6, didn't care about the correct syntax and generated incorrect message maps.