Access members of another class?

  • Thread starter Thread starter sweetjones
  • Start date Start date
  • Tags Tags
    Class Members
Click For Summary
SUMMARY

The discussion centers on accessing a member variable from one class in another class using Visual Studio C++ 2005 with MFC. The user is attempting to transfer a CString variable, m_CustName, from a CFormView class to set the title of a subsequent dialog. The issue arises from using an incorrect pointer object to access the member variable, leading to an Unhandled Exception. The solution involves ensuring the correct pointer is utilized to reference the desired class instance.

PREREQUISITES
  • Understanding of MFC (Microsoft Foundation Classes) and CFormView classes
  • Familiarity with CString and CEdit controls in Visual Studio C++
  • Knowledge of pointer usage in C++
  • Basic debugging skills in Visual Studio to handle exceptions
NEXT STEPS
  • Review MFC documentation on CFormView and dialog management
  • Learn about pointer manipulation and memory management in C++
  • Explore exception handling techniques in Visual Studio C++
  • Investigate best practices for data transfer between classes in MFC applications
USEFUL FOR

Software developers working with MFC in Visual Studio, particularly those dealing with class interactions and dialog management in C++ applications.

sweetjones
Messages
44
Reaction score
0
I'm using VS C++ 2005 in MFC, and I'm trying to access a member of another class. I'll try and make this as short as possible and still give the whole picture of what I am trying to do. I created a SDI with the CFormView Class. I have a dialog with an edit control box with a CString variable(m_CustName) and a CEdit control(m_CtrlCustName). I've done this to store the name(m_ctrlCustName.GetWindowTextW(m_sCustName);). I have a button to go to the next dialog which is another CFormView Class. What I'm trying to do is take that m_CustName variable, for example, "John Doe," and make that the title of the next dialog when I click that button. This is just a piece of what I have in the next View Class, but it is not working:
CString strTitle = CustName->m_sCustName; // CustName is a pointer object of the first class
pDoc->SetTitle(strTitle); // pDoc is declared as a pointer object to my document class already
My program compiles, but when I press the button to go to the next dialog a Unhandled Exception pops up, and the "atlsimplestr.h" shows. Well, any help is appreciated. Let me know if you need more clarification or info. Thanx in Advance!
 
Technology news on Phys.org
I figured out my problem. I was using the wrong *pointer object.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 5 ·
Replies
5
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
Replies
5
Views
8K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
7K
  • · Replies 19 ·
Replies
19
Views
5K