473,387 Members | 1,485 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

compiler synthesized constructors/copy constructors/assignment operators

Hi,

I understand that if I define a constructor, then the compiler won't
synthesize any constructor for me. How about copy constructor and
assignment operator? WIll compiler stop synthesizing any of them if I
declare a constructor or something else?

Thanks,
Jess

Jun 6 '07 #1
5 3690
Jess wrote:
Hi,

I understand that if I define a constructor, then the compiler won't
synthesize any constructor for me. How about copy constructor and
assignment operator? WIll compiler stop synthesizing any of them if I
declare a constructor or something else?

Thanks,
Jess
No - it will create defaults for any one you do not define yourself.

--
[there are no x's in my email]

I have the right to remain silent
(and should probably use it as much as possible)
Anything I type can and will be used against me
in a court of idiocy
I have the right to be wrong
(and probably am)
If I can not furnish my own wrongness
I'm sure someone will provide it for me.
Jun 6 '07 #2
Devon Null wrote:
Jess wrote:
>Hi,

I understand that if I define a constructor, then the compiler won't
synthesize any constructor for me. How about copy constructor and
assignment operator? WIll compiler stop synthesizing any of them if
I declare a constructor or something else?

Thanks,
Jess

No - it will create defaults for any one you do not define yourself.
Depends on whether it can be done. For example, copy assignment op
is impossible to generate if there's a data member who's a reference,
IIRC.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 6 '07 #3
I understand that if I define a constructor, then the compiler won't
synthesize any constructor for me. How about copy constructor and
assignment operator? WIll compiler stop synthesizing any of them if I
declare a constructor or something else?

No - it will create defaults for any one you do not define yourself.
It's a bit more complicated than that. If you write any of your own
constructors, the compiler will not generate a default constructor for
you (see 12.1/5). Also, if you have a template constructor taking a
single parameter, I believe that the compiler will still generate an
implicit copy constructor even if the template version would otherwise
be able to take the same parameter as the copy constructor. Anyone
able to provide evidence for or against this in the standard? The
closest I can find is 14.5.2/2, but that is talking about which one is
called when a template and non-template member function are both
present with the same name, not constructors specifically.

--
Computational Fluid Dynamics, CSIRO (CMIS)
Melbourne, Australia

Jun 6 '07 #4
Craig Scott wrote:
[..] if you have a template constructor taking a
single parameter, I believe that the compiler will still generate an
implicit copy constructor even if the template version would otherwise
be able to take the same parameter as the copy constructor. Anyone
able to provide evidence for or against this in the standard? The
closest I can find is 14.5.2/2, but that is talking about which one is
called when a template and non-template member function are both
present with the same name, not constructors specifically.
12.8/3, the second sentence.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 6 '07 #5
Jess wrote:
Hi,

I understand that if I define a constructor, then the compiler won't
synthesize any constructor for me. How about copy constructor and
assignment operator? WIll compiler stop synthesizing any of them if I
declare a constructor or something else?

No, if you define ANY constructor, the implicit default constructor is
omitted. If you don't define a copy constructor, a copy constructor
is generated. The latter is true for the copy-assignment operator.

Jun 7 '07 #6

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

Similar topics

42
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
1
by: Russ Ford | last post by:
Hi all, I'm trying to get inheritance and constructors clear in my head (and in my code). I have the following inheritance situation (all derivations public): A is the base class B is...
1
by: masood.iqbal | last post by:
I have a few questions regarding overloaded typecast operators and copy constructors that I would like an answer for. Thanks in advance. Masood (1) In some examples that I have seen...
10
by: utab | last post by:
Dear all, So passing and returning a class object is the time when to include the definition of the copy constructor into the class definition. But if we don't call by value or return by value, ...
25
by: tsaar2003 | last post by:
Hi Pythonians, To begin with I'd like to apologize that I am not very experienced Python programmer so please forgive me if the following text does not make any sense. I have been missing...
3
by: ennio | last post by:
Hi, i have a doubt i can't solve right now. Your help will be appreciated. I am studying constructors/copy constructors/destructors. I created this a little class (see below). If i comment the...
8
by: rKrishna | last post by:
I was trying to understand the real need for copy constructors. From literature, the main reason for redfinition of copy constructor in a program is to allow deep copying; meaning ability to make...
2
by: gyarnell | last post by:
Just ran into a problem upgrading from GCC 2.96 to GCC 3.3.2. There is a bug somewhere, could be in 2.96, could be in 3.3.2, could be in the code I'm compiling. Here's a minimal example class A {...
1
by: Kambehba | last post by:
Would you please tell me that if the Base class constructors and assignment operators are inherited by the derived classes or not. and any more information that apply. Thank you. kambiz
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...

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.