473,624 Members | 2,305 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Default functions implemented by compiler

This question seems to be silly. Can ony one figure out the default
functions implemented by compiler when we decalre a class like

class A
{

}

According to me this declaration will define default functions like

1. Default Constructor
2. Default Destrucor
3. Copy Constructor

Is there any other functions i am missing?

Jun 29 '06 #1
22 2424

su****@gmail.co m wrote:
This question seems to be silly. Can ony one figure out the default
functions implemented by compiler when we decalre a class like

class A
{

}
class A
{
};

According to me this declaration will define default functions like

1. Default Constructor
2. Default Destrucor
3. Copy Constructor

Is there any other functions i am missing?


No

Jun 29 '06 #2
"Salt_Peter " <pj*****@yahoo. com> writes:
su****@gmail.co m wrote:
This question seems to be silly. Can ony one figure out the default
functions implemented by compiler when we decalre a class like


class A
{
};
According to me this declaration will define default functions like
1. Default Constructor
2. Default Destrucor
3. Copy Constructor

Is there any other functions i am missing?


No


I disagree!

Scott Meyers writes in Effective C++ chapter 5 that
also the copy assignment operator may be generated.

Note that the listed functions are generated only when needed.
Best wishes

Jun 29 '06 #3
"Marco Wahl" <ma********@gma il.com> schrieb im Newsbeitrag
news:11******** **************@ x69g2000cwx.goo glegroups.com.. .
"Salt_Peter " <pj*****@yahoo. com> writes:
su****@gmail.co m wrote:
This question seems to be silly. Can ony one figure out the default
functions implemented by compiler when we decalre a class like


class A
{
};
According to me this declaration will define default functions like
1. Default Constructor
2. Default Destrucor
3. Copy Constructor

Is there any other functions i am missing?


No


I disagree!

Scott Meyers writes in Effective C++ chapter 5 that
also the copy assignment operator may be generated.

Note that the listed functions are generated only when needed.


It should also be mentioned that there is no "default destructor". There
only is a default implementation. A "default constructor" is any
constructor, which can be called without any arguments. It is called
"default" because it is used when no other constructor is explicitly
specified when an object is created, not because its implementation is
provided by the compiler.

Heinz

Jun 29 '06 #4
Hi
"Salt_Peter " <pj*****@yahoo. com> writes:
su****@gmail.co m wrote:
This question seems to be silly. Can ony one figure out the default
functions implemented by compiler when we decalre a class like


class A
{
};
According to me this declaration will define default functions like
1. Default Constructor
2. Default Destrucor
3. Copy Constructor

Is there any other functions i am missing?


No


I disagree!

Scott Meyers writes in Effective C++ chapter 5 that
also the copy assignment operator may be generated.


That's right. An operator== function is always implemented by the compiler
if none exists. This is always a bit-by-bit copy. Else this wouldn't be
possible:

void fun()
{
A a;
A b;
a = b;
}

Ciao,
Marco
Jun 29 '06 #5
Marco wrote:
Scott Meyers writes in Effective C++ chapter 5 that
also the copy assignment operator may be generated.

That's right. An operator== function is always implemented by the compiler
if none exists.


ITYM "operator="
This is always a bit-by-bit copy.


No, it isn't. It's a memberwise copy.

Jun 29 '06 #6

Rolf Magnus wrote:
Marco wrote:
Scott Meyers writes in Effective C++ chapter 5 that
also the copy assignment operator may be generated.


That's right. An operator== function is always implemented by the compiler
if none exists.


ITYM "operator="
This is always a bit-by-bit copy.


No, it isn't. It's a memberwise copy.


yes I agree Rolf. I have a query.
In an interview, they asked my friend about shallow and deep copy.
he could not explain because we never heard about that.

After that some one said..

deep copy happens through default constructor
and shallow copy is thru copy constructor. I think I did not match them
correctly.
plz correct which is deep and shallow.

and also said..

Copy constructor is dangerous. While programming with pointers, it may
lead to exception.
and shallow (copy constructor) will not have that problem.

Plz tell about this.

-- Murali Krishna.

Jun 29 '06 #7
Murali Krishna wrote:

Rolf Magnus wrote:
Marco wrote:
>> Scott Meyers writes in Effective C++ chapter 5 that
>> also the copy assignment operator may be generated.
>>
>
> That's right. An operator== function is always implemented by the
> compiler if none exists.
ITYM "operator="
> This is always a bit-by-bit copy.


No, it isn't. It's a memberwise copy.


yes I agree Rolf. I have a query.
In an interview, they asked my friend about shallow and deep copy.
he could not explain because we never heard about that.

After that some one said..

deep copy happens through default constructor
and shallow copy is thru copy constructor. I think I did not match them
correctly.
plz correct which is deep and shallow.


You are right that this definition is not correct.
A deep copy is a copy where the whole content of the object is copied, while
a shallow copy doesn't copy the data itself, but e.g. just its address, so
that the original object and the copy share their data.
The compiler-generated copy constructor does a deep copy. If you write your
own, you can do anything you want. The default constructor has nothing to
do with it.
and also said..

Copy constructor is dangerous. While programming with pointers, it may
lead to exception.
Well, if you have several objects that have a pointer to the same data, you
have to ensure that it's not deleted multiple times or used after being
deleted. However, failure to handle it correctly most often leads to
undefined behavior. An exception might be thrown, but typically isn't.
and shallow (copy constructor) will not have that problem.


Actually, it's just the shallow copy that has that problem, because it
usually means that after the copy operation, two objects have a pointer to
the same data. A deep copy is unproblematic in that respect, but might be
costly for large amounts of data.
Jun 29 '06 #8
Thanks for that.

-- Murali Krishna

Jun 29 '06 #9
* Rolf Magnus:
The compiler-generated copy constructor does a deep copy.


You mean, a shallow copy.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jun 29 '06 #10

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

Similar topics

0
2338
by: Anthony Baxter | last post by:
To go along with the 2.4a3 release, here's an updated version of the decorator PEP. It describes the state of decorators as they are in 2.4a3. PEP: 318 Title: Decorators for Functions and Methods Version: $Revision: 1.34 $ Last-Modified: $Date: 2004/09/03 09:32:50 $ Author: Kevin D. Smith, Jim Jewett, Skip Montanaro, Anthony Baxter
13
2188
by: I. Dancay | last post by:
Can someone help me work out this project? I need someone who is a C++ expert to help me work this one out. Here it is below. implement an abstract data > type (ADT) Student as a C++ class. The project > involves writing a program > that searches for duplicates in two files with lists > of student records. The > input files must be given sorted by student name. >
2
3775
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to produce two messages having the same message digest. That conjecture is false, as demonstrated by Wang, Feng, Lai and Yu in 2004 . Just recently, Wang, Yu, and Lin showed a short- cut solution for finding collisions in SHA-1 . Their result
44
2400
by: bahadir.balban | last post by:
Hi, What's the best way to implement an overloaded function in C? For instance if you want to have generic print function for various structures, my implementation would be with a case statement: void print_structs(void * struct_argument, enum struct_type stype) { switch(stype) { case STRUCT_TYPE_1:
47
3861
by: Albert | last post by:
So structures are useful to group variables, so you can to refer to a collection as a single entity. Wouldn't it be useful to also have the ability to collect variable and functions? Ask K&R say, C programs consist of variables to store the input and functions to manipulate them. This would make C object-oriented - how cool would that be? Are there any problems with adding the ability to have functions
4
9483
by: moleskyca1 | last post by:
Hi, In a recent discussion, some of us were in disagreement about the functions the C++ compiler generates. How many functions are generated by the compiler when you declare: class Foo { }; ?
13
2517
by: JohnQ | last post by:
The implementation of classes with virtual functions is conceptually easy to understand: they use vtables. Which begs the question about POD structs: how are they associated with their member functions in common implementations? And where is the 'this' ptr tucked away at for POD structs with member functions? John
39
2121
by: vlsidesign | last post by:
Operators seem similar to functions. They both do something to either arguments or operands, but are different in their syntax. Operators seem to be like built-in C functions. It would seem that there is very important reasons for having operands, and not just functions. Maybe they are just really powerful and can be used in expressions? Or they are somehow executed quicker than a function call? I am a newbie, and curious.. thanks for all...
8
1911
by: Grizlyk | last post by:
To continue some ideas of "C++ Archeology: Limits of OO paradigm", i want to ask about C++ development. There are C++ compilers, that has been written in old good C. Are C or pascal perfect languages that can be used to build any powerful OO language with mutable source representation, as C++ could be? Obviously no. Is current C++ can be used to build the OO language? Obviously no, because unfortunatelly C++ simultaneously is...
0
8238
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
8174
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8624
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
8336
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
8478
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6111
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5565
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
4082
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...
1
2607
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.