Thread: Creating a CMyEdit class with CEdit

  1. #1
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257

    Creating a CMyEdit class with CEdit

    Hi,

    I've created a CMyEdit class using CEdit as the base class, and I've defined my own OnSetFocus function. But Everytime I create an instance of CMyEdit it gives me an error
    Code:
    error C2065: 'CMyEdit' : undeclared identifier
    I haven't done this before and really don't know whether I've done all I was supposed to do. Could I have some assistance, please.
    Everything is relative...

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    You have included the header for MyEdit (MyEdit.h) in the file you want to declare the edit in?




    may need a pragma once or conditional compilation

    ie C style conditional compilation.....

    //include the file only once
    #ifndef MY_EDIT_CLASS //if not defined
    #define MY_EDIT_CLASS //define it
    #include "MyEdit.h"
    #endif //close the condition
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    what novacain said, and if you are using Microsoft Visual C++ and you have more than one .cpp files it can be a bit messed up, not too long ago i had problems with it.
    My Website
    010000110010101100101011
    Add Color To Your Code!

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    >>if you are using Microsoft Visual C++ and you have more than one .cpp files it can be a bit messed up, not too long ago i had problems with it.

    Just hit 'Rebuild All' or 'Clean'.

    If still problems, delete the contents of your Debug folder and use rebuild all.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    I have added the header file, but I can't properly overrider a base class function.

    Here's the whole class definition:
    Code:
    #include "stdafx.h"
    #include "Initial GUI.h"
    #include "MyEdit.h"
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    
    /////////////////////////////////////////////////////////////////////////////
    // CMyEdit
    
    CMyEdit::CMyEdit()
    {
    	void CMyEdit::OnSetfocus(CWnd* pOldWnd);  //CWnd* pOldWnd
    }
    
    CMyEdit::~CMyEdit()
    {
    }
    
    
    BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
    	//{{AFX_MSG_MAP(CMyEdit)
    	ON_CONTROL_REFLECT(EN_SETFOCUS, OnSetfocus)
    	//}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    /////////////////////////////////////////////////////////////////////////////
    // CMyEdit message handlers
    
    void CMyEdit::OnSetfocus(CWnd* pOldWnd) //CWnd* pOldWnd
    {
    	CString lstr, estr, str;
     
    	this->selectedEditControl = 1;
    
    	CListBox* pGetList = (CListBox*)this->GetParent()->GetDlgItem(IDC_LIST1);
    
    	pGetList->GetText((pGetList->GetCurSel()), lstr);
    		 
    	this->SetWindowText(lstr);
    	
    }
    I get this error
    Code:
    error C2244: 'CMyEdit::OnSetfocus' : unable to resolve function overload
    h:\gui\gui v1\myedit.cpp(37) : error C2511: 'OnSetfocus' : overloaded member function 'void (class CWnd *)' not found in 'CMyEdit'
    Everything is relative...

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    try....

    in prototype (header)

    afx_msg void OnSetfocus();

    or

    afx_msg void OnSetfocus(CWnd *pOldWnd);
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inherite nonvirtual class functionality
    By DrSnuggles in forum C++ Programming
    Replies: 2
    Last Post: 04-30-2009, 01:52 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. class member access denied
    By chiqui in forum C++ Programming
    Replies: 2
    Last Post: 05-27-2002, 02:02 PM
  4. I need help creating a string class
    By incognito in forum C++ Programming
    Replies: 1
    Last Post: 01-19-2002, 05:48 PM
  5. Creating a string class
    By incognito in forum C++ Programming
    Replies: 2
    Last Post: 01-19-2002, 05:40 PM