Access members of another class?

In summary, the conversation is about a programmer using VS C++ 2005 in MFC and trying to access a member of another class. They have created a SDI with a CFormView Class and have a dialog with an edit control box and a CEdit control. They have a button to go to the next dialog, and they are trying to use the m_CustName variable to set the title of the next dialog. However, they encountered an unhandled exception and realized that they were using the wrong pointer object.
  • #1
sweetjones
44
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
  • #2
I figured out my problem. I was using the wrong *pointer object.
 
  • #3


As a scientist, my response to this would be to first make sure that you are properly declaring and initializing your pointer object "CustName" in the second CFormView class. This could be the reason for the unhandled exception. Additionally, you may want to consider using a different approach to pass data between classes, such as using a global variable or a function to retrieve the data from the first class. It is important to carefully consider the design and structure of your code in order to avoid potential errors and improve efficiency.
 

1. How can I access members of another class?

In order to access members of another class, you can use the "dot" notation, which involves using the name of the class followed by a dot and then the name of the member you want to access.

2. Can I access private members of another class?

No, you cannot directly access private members of another class. Private members are not visible outside of the class they are declared in.

3. What is the difference between public and private members?

Public members can be accessed and modified from outside the class, while private members can only be accessed and modified from within the class.

4. How do I access protected members of another class?

Protected members can be accessed using the "dot" notation, just like public members. However, they can only be accessed by subclasses or classes within the same package.

5. Can I access static members of another class?

Yes, you can access static members of another class using the "dot" notation. However, you do not need to create an instance of the class to access static members.

Similar threads

  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
5
Views
6K
  • Programming and Computer Science
Replies
1
Views
2K
Replies
2
Views
2K
  • Programming and Computer Science
Replies
5
Views
5K
  • Programming and Computer Science
Replies
2
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
19
Views
4K
  • Programming and Computer Science
Replies
2
Views
6K
  • Programming and Computer Science
Replies
3
Views
4K
Back
Top