Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

VC++ User Function

Options
  • 30-01-2002 3:01pm
    #1
    Registered Users Posts: 2,781 ✭✭✭


    Hi,

    Using MS VC++ 6.0.

    I have written a simple function say its called MyFunction.
    Now I have a click event on a menu item
    void CTueDlg::OnFind()
    {
    MessageBox("Hello");
    MyFunction();

    }


    Now when I compile it blows up and says it doesn't recognise MyFunction.

    does anyone have any ideas >

    MyFunction is coded in the class file,

    thanks for any help

    amen


Comments

  • Closed Accounts Posts: 411 ✭✭Jay


    You'll have to make the function static, since dialog procedures are static.

    so redefine it in the header as

    static void myfunction();

    and at the top of the CPP file , where the #includes and #defines are, put

    void CTueDlg::myfunction();

    It doesn't have to be of type void of course.

    Let me know how you get on.


  • Registered Users Posts: 2,781 ✭✭✭amen


    I guess I am doing something wrong as I can't get it to work.

    I have TueDlg.cpp
    and at the top I have
    // TueDlg.cpp : implementation file
    //

    #include "stdafx.h"
    #include "Tue.h"
    #include "TueDlg.h"
    #include <afx.h>

    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    void CTueDlg::MyFunction();

    Then I have TueDlg.h
    and in that I have at the bottom

    static void MyFunction();
    //{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.

    #endif // !defined(AFX_TUEDLG_H__140F015D_0ABE_11D6_A39A_00001C0945B0__INCLUDED_)

    when I compile I get
    TueDlg.cpp(14) : error C2039: 'MyFunction' : is not a member of 'CTueDlg'

    any ideas ?


  • Closed Accounts Posts: 411 ✭✭Jay


    You must make the static function a member of the class.

    TueDlg.h

    #include ...
    #include ...
    #include ...

    class CTueDlg
    {
    public:

    private:
    static void MyFunction();

    }

    TueDlg.cpp

    #include "TueDlg.h"

    void CTueDlg::MyFunction();


    //constuctor..
    .............

    //destructor
    .............

    //Function definition
    void CTueDlg::MyFunction()
    {
    .........
    .........
    .........
    }


  • Registered Users Posts: 2,781 ✭✭✭amen


    Jay,

    that worked a treat.

    thanks very much for your help
    amen


Advertisement