Default Member Functions

M

Morris

I have a question.

How many functions are defined by default when you define a class.

I was aware of four functions:
Constructor
Destructor
Assignment Operator
Copy Contructor

I over heard somewhere that there are six functions by default in a class.

Can anyone please tell me what are the other two default functions in a class.

Regards,
morris
 
C

cyper

Morris said:
I have a question.

How many functions are defined by default when you define a class.

I was aware of four functions:
Constructor
Destructor
Assignment Operator
this one isn't always needed.
when it isn't exist.they would auto call copy construtor
 
K

Karl Heinz Buchegger

cyper said:
this one isn't always needed.
when it isn't exist.they would auto call copy construtor

Not sure what you mean with that, your english is very hard to understand.
But in any case it sounds wrong.

operator= and copy constructor do different things. The compiler
will never (and can't do it) substitute operator= with a call to
the copy constructor or vice versa. If it needs an operator= there
has to be one, or the compiler emits an error.
 
S

Sree

Also, it is doubtfull, that the compiler offers you a default constructor and
destructor, you need to explicitly put that in your code. There are wizards in
IDEs which will help you in this, but that is offtopic here.
 
H

Howard

Sree said:
Also, it is doubtfull, that the compiler offers you a default constructor and
destructor, you need to explicitly put that in your code. There are wizards in
IDEs which will help you in this, but that is offtopic here.

--

I think you're misunderstanding. The "default" constructor and/or
destructor are created if needed, but they are not created as source code
that gets inserted in your .cpp file. They are created in the resulting
object code, however. Suppose, for example, that your class contained and
instance of another class. The constructor for that contained class has to
be called, and that's done via the default constructor that's created for
your class (assuming you haven't provided one).

-Howard
 
P

Prateek R Karandikar

I have a question.

How many functions are defined by default when you define a class.

I was aware of four functions:
Constructor
Destructor
Assignment Operator
Copy Contructor

I over heard somewhere that there are six functions by default in a class.

Can anyone please tell me what are the other two default functions in a class.

Regards,
morris

The other 2 are the unary & and the comma operator. Note that only the
in-built or compiler-generated comma has the sequence point, not any
user-defined ones.

-- --
Abstraction is selective ignorance.
-Andrew Koenig
-- --
 
M

Morris

(e-mail address removed) (Prateek R Karandikar) wrote in message
The other 2 are the unary & and the comma operator. Note that only the
in-built or compiler-generated comma has the sequence point, not any
user-defined ones.

Thanx for the answer. Can someone please provide me pointer to some
text(preferably electronic) where I can get more info on the same.

Or some section of Stroustrup's book which gives info regarding the
same.

Regards,
morris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top