Mar 3, 2010 at 2:24pm UTC
if i have a class that stores 3 integers, is it true that using the default bitwise copy constructor would be faster then overloading the assignment operator and explicitly transfering the integers over?
Mar 3, 2010 at 3:59pm UTC
The default copy constructor is NOT bitwise. It calls the copy constructors of every element for you.
Mar 4, 2010 at 9:18am UTC
would the default copy constructor be faster then the (explicit) one we would write?
Mar 4, 2010 at 10:06am UTC
It would not be slower.
1 2 3 4 5 6
struct A { int a,b; };
struct B { int a,b; B(const B& x):a(x.a),b(x.b){} };
...
A a1; B b1;
A a2(a1);
B b2(b1);
I wouldn't be surprised if the last two lines yield in exact the same machine code.
However, this may (or may not be) be faster:
1 2 3 4
struct C { int a,b; }
...
C c1;
C c2; memcpy(&c2, &c1, sizeof (c1));
Last edited on Mar 4, 2010 at 10:08am UTC