Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

VC++ User Function

  • 30-01-2002 03:01PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 2,781 ✭✭✭amen


    Jay,

    that worked a treat.

    thanks very much for your help
    amen


Advertisement