| View previous topic :: View next topic |
| Author |
Message |
Morris Guest
|
Posted: Thu Jun 24, 2004 6:31 am Post subject: Default Member Functions |
|
|
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
|
|
| Back to top |
|
 |
cyper Guest
|
Posted: Thu Jun 24, 2004 7:17 am Post subject: Re: Default Member Functions |
|
|
"Morris" <lattice (AT) flashmail (DOT) com> ????
news:3e2b79b0.0406232231.6f8169ab (AT) posting (DOT) google.com...
| Quote: | 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
| Quote: | 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
|
|
|
| Back to top |
|
 |
Karl Heinz Buchegger Guest
|
Posted: Thu Jun 24, 2004 8:18 am Post subject: Re: Default Member Functions |
|
|
cyper wrote:
| Quote: |
"Morris" <lattice (AT) flashmail (DOT) com> ????
news:3e2b79b0.0406232231.6f8169ab (AT) posting (DOT) google.com...
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
|
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.
--
Karl Heinz Buchegger
[email]kbuchegg (AT) gascad (DOT) at[/email]
|
|
| Back to top |
|
 |
Sree Guest
|
Posted: Thu Jun 24, 2004 11:15 am Post subject: Re: Default Member Functions |
|
|
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.
--
Use our news server 'news.foorum.com' from anywhere.
More details at: http://nnrpinfo.go.foorum.com/
|
|
| Back to top |
|
 |
Howard Guest
|
Posted: Thu Jun 24, 2004 6:55 pm Post subject: Re: Default Member Functions |
|
|
"Sree" <no_spam_please (AT) f-m (DOT) fm> wrote
| Quote: |
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
|
|
| Back to top |
|
 |
Prateek R Karandikar Guest
|
Posted: Thu Jun 24, 2004 11:38 pm Post subject: Re: Default Member Functions |
|
|
[email]lattice (AT) flashmail (DOT) com[/email] (Morris) wrote in message news:<3e2b79b0.0406232231.6f8169ab (AT) posting (DOT) google.com>...
| Quote: | 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
-- --
|
|
| Back to top |
|
 |
Morris Guest
|
Posted: Sun Jun 27, 2004 1:44 pm Post subject: Re: Default Member Functions |
|
|
[email]kprateek88 (AT) yahoo (DOT) com[/email] (Prateek R Karandikar) wrote in message
| Quote: | 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.
|
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
| Quote: |
-- --
Abstraction is selective ignorance.
-Andrew Koenig
-- --
|
|
|
| Back to top |
|
 |
|