473,404 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

private datamember access control

Hi,

I don't understand one thing when authoring cp ctor. The below is simplified
class and cp constructor.
When initializing the data member, we use object ref TEST to access its
private member m_x. Why in this case it's allowed even m_x is private member
of object TEST?

Thanks very much!

John

class test
{
private:
int m_x;
public:
test(const test& TEST):m_x(TEST.m_x)
{

}
}
Jul 22 '05 #1
3 1389
On Thu, 05 Feb 2004 13:58:38 GMT in comp.lang.c++, "john sun"
<jo*****@sbcglobal.net> was alleged to have written:
When initializing the data member, we use object ref TEST to access its
private member m_x. Why in this case it's allowed even m_x is private member
of object TEST?


You are the author of class test; you are trusted to not violate the
requirements for accessing class test members. Access control is by
class, not by instance.

Jul 22 '05 #2
Very good point.
Thanks!
"David Harmon" <so****@netcom.com> wrote in message
news:40****************@news.west.earthlink.net...
On Thu, 05 Feb 2004 13:58:38 GMT in comp.lang.c++, "john sun"
<jo*****@sbcglobal.net> was alleged to have written:
When initializing the data member, we use object ref TEST to access its
private member m_x. Why in this case it's allowed even m_x is private memberof object TEST?


You are the author of class test; you are trusted to not violate the
requirements for accessing class test members. Access control is by
class, not by instance.

Jul 22 '05 #3
On Thu, 05 Feb 2004 13:58:38 +0000, john sun wrote:
Hi,

I don't understand one thing when authoring cp ctor. The below is simplified
class and cp constructor.
When initializing the data member, we use object ref TEST to access its
private member m_x. Why in this case it's allowed even m_x is private member
of object TEST?


Members are *class* private, not *object* private. One object can touch
the internals of other objects of the same class. The reason is mainly so
code like yours is allowed. If it was not allowed, copy constructors and
assignment operators would be a pain to write.

HTH,
M4

Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Martin Vorbrodt | last post by:
Example code in one of my books intrigues me: class B { public: B* Clone() const { B* p = DoClone(); assert(typeid(*p) == typeid(*this)); return p; }
10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
3
by: Alvaro E. Gonzalez V. | last post by:
Hello!!! I'm building a control that in a property assign a Dataset which they are initialized and another property Like DataMember. Similar as it happens to the DataSource property of a...
6
by: Beorne | last post by:
I have to use XmlSerializer to serialize a class and I've found big problems serializing properties and indexers. I assumed that if you serialize a class with public properties (or an indexers)...
1
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
In the Visual Studio 2005 designer, I have a grid, a binding source, and a data set which contains two data tables. In the Designer, I make the settings below. If I set the DataMember for the...
0
by: mzwilli | last post by:
Hi, I'm trying to create browsable DataSource and DataMember properties on a user control. The idea is to create a descendent object, place a dataset then specify the DataSource (DataSet) and...
13
by: PragueExpat | last post by:
I (think) that I've come up with a pattern that I haven't seen in any publications so far and I would like some feedback. Basically, I was looking for a way to inherit private functions and I came...
0
by: Dave Raskin | last post by:
I am trying to specify a logical default value for a in a WCF Web Service using basicHttpBinding. I realize that the language defaults are: int - 0 string - null bool - false enum - ?
0
by: Dave Raskin | last post by:
Hello, I am trying to specify a logical default value for a in a WCF Web Service using basicHttpBinding. I realize that the language defaults are: int - 0 string - null bool - false
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.