CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 1999
    Posts
    9

    How to call a member function of a class from a member function of another class

    I have problems when calling a member function of a class ( if i do not define this function as member i cannot use the pointer for the recordset) within another class
    CResultDlg is a dialog class where i call by pressing a button and using .DoModal(); And also CNewWordsView::find_random_record(); phrase gets error. I searched help but could not find how to call a member function from another class.
    Thank you.


    #My programs name is NewWords and i have created it with App.Wizard
    #in NewWordsView.cpp
    void CNewWordsView::find_random_record()
    {
    srand( (unsigned)time( NULL ) );
    int random_num=rand();
    m_pSet->MoveFirst();
    m_pSet->MoveLast();
    int max_record=m_pSet->GetRecordCount();
    m_pSet->MoveFirst();
    int decimal, sign;
    char *buffer;
    double result;
    result=(random_num/32500)*max_record;
    buffer = _fcvt( result, 7, &decimal, &sign );
    int record_pos=atoi(buffer);
    if (record_pos!=(max_record-1))
    { m_pSet->Move(record_pos);
    }
    else
    {
    m_pSet->Move(record_pos-1);
    }

    }


    void CResultDlg::OnBtn_Vote()
    {
    CNewWordsView::find_random_record();
    }





  2. #2
    Join Date
    May 1999
    Location
    Seattle, WA USA
    Posts
    423

    Re: How to call a member function of a class from a member function of another class

    to call the function like
    CNewWordsView::find_random_record();
    from anywhere in the program, CNewWordsView::find_random_record would have to be defined static, but that would make you unable to use your m_pSet member variable. For the function to be called as written, you need an instance of your CNewWordsView class that your dialog can use to call the function find_random_record. Do you have an instance of that class around when you call DoModal? Perhaps you can pass it in to your CResultDlg class, or access it via GetParent () from within your CResultDlg::OnBtn_Vote() function.

    If you could post more of the code, or explain the surrounding situation a little better, perhaps I (or someone else) can be more helpful.

    HTH
    --michael


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured