Access members of another class?

  • Thread starter Thread starter sweetjones
  • Start date Start date
  • Tags Tags
    Class Members
AI Thread Summary
The discussion revolves around a user working with Visual Studio C++ 2005 and MFC, trying to pass a CString variable (m_CustName) from one CFormView dialog to another. The user aims to set the title of the next dialog to the value of m_CustName when a button is clicked. Initially, the code compiles but results in an unhandled exception when the button is pressed, indicating an issue with pointer usage. The user later identifies that the problem stemmed from using the wrong pointer object to access the variable. This highlights the importance of correctly managing pointers and object references in MFC applications to avoid runtime errors.
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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top