473,804 Members | 3,750 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

When copy object of class type, all members shouldn't be non-public?

--------- quotation ---------
The default method of initialization using special member functions is
to perform a bit-for-bit copy from the initializer into the object to
be initialized. This technique is applicable only to:
1. Objects of built-in types.
2. Pointers.
3. References.
4. Objects of class type, where the class has no private or protected
members, no virtual functions, and no base classes.
--------- of of quotation ---------

I saw these description when read some documents.

Does the fourth item says that when perform initialization using copy
ctor or assignment using operator =, all members of the class can't be
non-public. For example do this:

//Class C1;
C1 o;

C1 o2 = o;
o2 = o;
But even though deriving from a base class, there isn't such a
limitation. Why the limitation can be applied for copying object from a
same class type? Is it true in iso/iec 14882?

Jul 23 '05 #1
1 1445
lovecreatesbeau ty wrote:

--------- quotation ---------
The default method of initialization using special member functions is
to perform a bit-for-bit copy from the initializer into the object to
be initialized. This technique is applicable only to:
1. Objects of built-in types.
2. Pointers.
3. References.
4. Objects of class type, where the class has no private or protected
members, no virtual functions, and no base classes.
--------- of of quotation ---------

When a point 5 is added (And I guess the author ment it to be that way)
5. Objects of class type, where each data member is a POD
then the whole thing is the descirption of what a POD is.

POD = Plain Old Data structre

or in other words: A struct as it was in C. A collection of members
without anything special.
I saw these description when read some documents.

Does the fourth item says that when perform initialization using copy
ctor or assignment using operator =, all members of the class can't be
non-public.


No. It just says that only in that case the compiler will do a bit-for-bit
initialization (or assignment). What the author didn't say: In all other cases
a memberwise copy or assignment is done.

In practice this isn't something you have to worry about. The compiler will
initialize a class the right way. Only in some cases he can use a somewhat
faster method.

--
Karl Heinz Buchegger
kb******@gascad .at
Jul 23 '05 #2

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

Similar topics

6
46912
by: Matthew Louden | last post by:
The following ASP code yields the following error, but actually the new record is stored in database. The same error happens when the application deletes a record, such as sqlStmt ="delete from test where username='2323'" Any ideas? Thanks! <% Dim objRS, sqlStmt Set objRS = Server.CreateObject ("ADODB.Recordset") sqlStmt = "insert into test VALUES ('2341', '2341');"
3
2048
by: Nico Massi | last post by:
Hi NG! I have a class A that should store a vector of pointers to objects of class B. But class B contains a template argument and each of the stored objects in class A could have a different template argument. So i need a way to store an array of template objects in a non-template class. Obviously this wont work cause a can`t tell the compiler which template argument to use. So whats the usual way to solve such a situation?
3
2200
by: Rob F | last post by:
I am trying to compile a string class which was working before but subsequent attempts to make it more 'object orientated' (privatizing the member variables and implenting query functions) it refuses to compile in Visual C++. Here is the code: http://www.rbf.org.uk/xstring.h When compiling I get the following: \xstring.h(87) : error C2662: 'query_length' : cannot convert 'this'
5
2576
by: BigMan | last post by:
Does the standard define the order in which static members of a class are created and initialized?
5
19081
by: Muskito | last post by:
Hi, Is it possible to copy the entire List(Of type) object to another List(Of type) object (they are both of the same type ofcourse) - without keeping the reference? There's the CopyTo method, but it only copies the data to a flat array. I Need this for Backup in my program, when i update the master list and
2
9872
by: AdawayNoSpam | last post by:
Said that I have the following class Class MyRootClass(Of T) End Class Class MySubClass1(Of T) Inherits MyRootClass(Of T) End Class
13
2426
by: docschnipp | last post by:
Hi, I have a bunch of object derived from the same base class. They all share the same constructor with some parameters. Now, instead of using a large switch() statement where I call every single Object by itself, I'd like to assign a reference to the class type and call it later without knowing the derived type. Example:
2
2466
by: pvl_google | last post by:
Hi, I'm trying to extend an STL class with additional iterator functionality. In the simplified example below I added an extra iterator class with a dereferencing operator. This operator internally relies on the at function of the superclass. #include <vector>
1
5601
by: ztycho | last post by:
Could someone explain if the following gcc 4.1 compile error is working as designed and, if so, why does the second version of the code not fail? Failing case: ====================================== struct A { int GetId() const; };
2
30407
by: kino | last post by:
Hello, I am getting the following error 25 C:\Dev-Cpp\main.cpp request for member `no' in `one', which is of non-class type `box' in the code while (!myfile.eof()) {
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10583
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10337
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9160
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.