?
Solved

Accessing another objects private member!

Posted on 1999-11-30
1
Medium Priority
?
217 Views
Last Modified: 2010-04-01
class Node;

class Node
{
private:
  long m_nVal;
  Node *m_pNext;
}

Node *pNode = new Node();

assuming m_pNext points to a valid node,

pNode->m_pNext->m_nVal;

succeeds, even though m_nVal is a private member of m_pNext.

Does this mean that a class is a friend of itself automatically, so an object of a class can access private members of another object of the same class?

0
Comment
Question by:frogpassword
1 Comment
 

Accepted Solution

by:
_keithr earned 20 total points
ID: 2245658
yes
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question