Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Guys, m_strMessage is a control variable of my parent class named CsocketDlg. And m_sFrameLB is a control variable of my modeless MFC class named CSetThresholdFineDfLB. Now by checking a conditon I wanna pass a string that is stored in m_sFrameLB to m_strMessage. i should write this code under a buttonclick of my child modeless dialog. Here is my code:

C#
void CSetThresholdFineDfLB::OnClickedIdapply()
{
    // TODO: Add your control notification handler code here
      //CString commandcodelb,framelb;
      //int tvlb;
     // commandcodelb = m_sCommandCode;
      //tvlb = m_iThresholdValue;

      if(m_iThresholdValue==0)
      {

          SetDlgItemText(IDC_FineDfLBFrame, _T("C901A3"));
          CsocketDlg.m_strMessage = m_sFrameLB;

      }
      else
          SetDlgItemText(IDC_FineDfLBFrame, _T("INVALID TV"));

     // UpdateData(FALSE);
}


When i wrote this line "CsocketDlg.m_strMessage = m_sFrameLB;", I got the error:
a non static member reference must be relative to a specific object. Please help me. Also I included parent class header file in child.cpp file.
Posted
Updated 19-Mar-14 7:21am
v2
Comments
Sergey Alexandrovich Kryukov 19-Mar-14 13:17pm    
Between classes? what would it supposed to mean? Do you understand what is class and what is its instance (object)?
Why would you need any help here? Do you know how instance functions and fields work?
—SA

1 solution

Please see my comment to the question. It's quite appear that you don't understand what classes are and why do you use them. I can answer, but I don't think it can help you unless you step back and learn at least a bit about classes and their instances, and also about "static".

C++
// It cannot compile because m_strMessage is non-static. It belongs to instance, not class: 
//CsocketDlg.m_strMessage = m_sFrameLB;

// you need some instance:
CsocketDlg myDlg = // whatever
myDlg.m_strMessage = //... will compile

// of
CsocketDlg * myDlgPointer = // whatever
myDlgPointer -> m_strMessage = //... will compile

But you also need enough access to this member. Alternatively, you could have static field, which could be accessed via the class — not recommended! It's too early to explain why; first, you need to learn about classes. At this moment, you have no clue. Don't worry, you will learn it soon. Just do it.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900