Copy constructor: why can't I copy objects as if they were structs?

J

Jacek Dziedzic

Victor said:
Jacek said:
Victor Bazarov wrote:
A C++ practitioner should only use the term "bitwise" when talking about
the binary operators &, |, and ^, and the unary ~.

V



How about bitset::eek:perator[]? :>


That overloaded operator is called "indexing". I would expect a C++
programmer to be familiar with it under that name.

I know, but isn't the manner in which it indexes bit-wise?

- J.
 
V

Victor Bazarov

Jacek said:
Victor said:
Jacek said:
Victor Bazarov wrote:

A C++ practitioner should only use the term "bitwise" when talking
about
the binary operators &, |, and ^, and the unary ~.

V




How about bitset::eek:perator[]? :>



That overloaded operator is called "indexing". I would expect a C++
programmer to be familiar with it under that name.


I know, but isn't the manner in which it indexes bit-wise?

Well, as opposed to what? Indexing them logically? Indexing them whole?
 
G

Guest

Victor said:
You use sentences that are too long for my feeble brain.

class A { A(A&); }; // private copy c-tor
class B { A a; }; // not copy-constructible - 'a' cannot be copied
class C { B b; }; // no user-defined copy c-tor
void foo(C& c) {
C cc(c); // ill-formed
}

For the class C the compiler cannot create a copy-c-tor because 'b' does
not have "default" copy semantics because 'A' doesn't.. A program that
needs copy-construction of a 'B' or a 'C' is ill-formed.

class A { A(A&); }; // private copy c-tor
class B { A& a; }; // no user-defined copy c-tor, but 'a' can be copied
class C { B b; }; // no user-defined copy c-tor, but 'b' can be copied
void foo(C& c) {
C cc(c); // perfectly OK
}

'B' is perfectly copy-constructible, and so is 'C'. There is the issue
of constructing an object of type 'B' to begin with, but it's not what we
are talking about here.

Thank you for your great patience. You gave me explenation I tried to
ask for. Simply, I couldn't express my question as simple as I should.
Why? I'm not sure, may be I didn't understand the problem as I should
firt. Now, I know what you had in mind in your previous post.
Thank you
 
R

Ron Natalie

rdc02271 said:
Hello!
Is this too crazy or not?
Copy constructor: why can't I copy objects as if they were structs?
I have a set of simple objects (no string properties, just integers,
doubles) and I have to copy the same object millions of times.
So instead of writing in the copy constructor
property1=SourceObject.property1 can't I use memory copy functions to
do this faster?
Is this too stupid?
By the way, I'm a C++ newbie! But don't go easy on me just because...
;)
If you cannot afford a copy constructor, one will be appointed for
you before questioning.

The compiler generates a copy constructor if the user doesn't define
one. If there are no subobjects that themselves have copy constructors
it almost certainly does a very fast block copy of the object.
 
J

Jacek Dziedzic

Victor said:
Jacek said:
Victor said:
Jacek Dziedzic wrote:

Victor Bazarov wrote:

A C++ practitioner should only use the term "bitwise" when talking
about
the binary operators &, |, and ^, and the unary ~.

V





How about bitset::eek:perator[]? :>




That overloaded operator is called "indexing". I would expect a C++
programmer to be familiar with it under that name.



I know, but isn't the manner in which it indexes bit-wise?


Well, as opposed to what? Indexing them logically? Indexing them whole?

As opposed to nothing, actually. What I meant to say was that
a "C++ practitioner" could easily use the word "bitwise" in
contexts other than involving "bitwise operators" that you
have mentioned.

My point was that a statement like
"the bitset::eek:perator[] overloaded operator allows for bitwise
access to the bitset" would be pretty legal.

But in fact I won't argue.

eot,
- J.
 

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

Forum statistics

Threads
473,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top