| View previous topic :: View next topic |
| Author |
Message |
sujilc@gmail.com Guest
|
Posted: Thu Jun 29, 2006 9:10 am Post subject: 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? |
|
| Back to top |
|
 |
Marco Guest
|
Posted: Thu Jun 29, 2006 9:10 am Post subject: Re: Default functions implemented by compiler |
|
|
Hi
| Quote: | "Salt_Peter" <pj_hern (AT) yahoo (DOT) com> writes:
sujilc (AT) gmail (DOT) com 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 |
|
| Back to top |
|
 |
Heinz Ozwirk Guest
|
Posted: Thu Jun 29, 2006 9:10 am Post subject: Re: Default functions implemented by compiler |
|
|
"Marco Wahl" <marco.wahl (AT) gmail (DOT) com> schrieb im Newsbeitrag
news:1151561652.292271.291580 (AT) x69g2000cwx (DOT) googlegroups.com...
| Quote: | "Salt_Peter" <pj_hern (AT) yahoo (DOT) com> writes:
sujilc (AT) gmail (DOT) com 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 |
|
| Back to top |
|
 |
Marco Wahl Guest
|
Posted: Thu Jun 29, 2006 9:10 am Post subject: Re: Default functions implemented by compiler |
|
|
"Salt_Peter" <pj_hern (AT) yahoo (DOT) com> writes:
| Quote: | sujilc (AT) gmail (DOT) com 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 |
|
| Back to top |
|
 |
Salt_Peter Guest
|
Posted: Thu Jun 29, 2006 9:10 am Post subject: Re: Default functions implemented by compiler |
|
|
sujilc (AT) gmail (DOT) com wrote:
| Quote: | 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
{
};
| Quote: |
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 |
|
| Back to top |
|
 |
Rolf Magnus Guest
|
Posted: Thu Jun 29, 2006 9:10 am Post subject: Re: Default functions implemented by compiler |
|
|
Marco wrote:
| Quote: | 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="
| Quote: | This is always a bit-by-bit copy.
|
No, it isn't. It's a memberwise copy. |
|
| Back to top |
|
 |
Murali Krishna Guest
|
Posted: Fri Jun 30, 2006 9:10 am Post subject: Re: Default functions implemented by compiler |
|
|
Andrey Tarasevich wrote:
| Quote: | They are not called "default" functions. They are called "implicitly
declared/implicitly defined" functions.
|
OK there are function declared/implemented by default or what ever..
We get them just after creating a class. I think it is the same case in
java.
| Quote: | More precisely, I don't see any program at all, therefore there's no way to
say whether they will be defined or not.
|
as in other thread.. (plz dont correct me if it is not a thread)
http://groups.google.co.in/group/comp.lang.c++/browse_thread/thread/fecc7cb4f3405d69/ba0c0fb2b18d6f68#ba0c0fb2b18d6f68
Tom Widmer wrote:
| Quote: | void Foo_f(Foo* this)
{
printf("%d\n", this->i);
}
|
Foo is a class
| Quote: | Conceptually, the object you are calling the member function on is
passed as a hidden parameter to the function, named "this".
So see that C++ classes and member functions are really just "syntatic
sugar" for C structs and normal functions
|
that's excellent understanding.
OK my query is..
If that is the case for 'this', what is it for other default/implicitly
implemented functions?
will a default constructor be generated by compiler with C code?
and the same for destructor and '=' operator?
what is the implementation for those functions?
Plz expalin. |
|
| Back to top |
|
 |
Murali Krishna Guest
|
Posted: Sat Jul 01, 2006 9:10 am Post subject: Re: Default functions implemented by compiler |
|
|
Hi Andrey,
Thanks for your answers.
Andrey Tarasevich wrote:
| Quote: | It would be "what ever" if "default" was just an English word. But in
this context it is not just a word. In C++ terminology it is a term with
concrete meaning.
|
I agree that they are not 'default' but we are used to that.
| Quote: | Hmm... You wording is unclear. 'this' is not a function. As Tom
explained, 'this' is a name of an implicit parameter present in every
non-static member function of a class. All non-static member functions
have it. Whether they are implicitly defined or user-defined makes no
difference.
..
|
Ok I came to know about one more point. Thanks for that.
| Quote: | will a default constructor be generated by compiler with C code?
and the same for destructor and '=' operator?
C code? What exactly do you mean by "C code" in this case? There's no
such thing as "classes" or "member functions" in C language.
|
I read in that thread..
| Quote: | earlier versions of C++ compilers first converted C++ code into C code.
|
I dont think it will happen in present C++ compilers.
I just wanted to understand how the compiler implements those functions
after just declaring a class.
Thanks any way.
-- Murali Krishna |
|
| Back to top |
|
 |
Sekhar Guest
|
Posted: Mon Jul 03, 2006 9:10 am Post subject: Re: Default functions implemented by compiler |
|
|
| Quote: | #include <string
#include <string
int main()
{
std::string original;
unsigned char *p_buf = new unsigned char[sizeof(std::string)];
/* Copying goes here */
new(p_buf) std::string(original);
|
Thanks for making concepts more clear. This code snippet gives me
more thoughts on new operator. Can you just breif on how new operator
works on the above statement. |
|
| Back to top |
|
 |
|