Solved

Shallow copy with no assignment operator

Posted on 2006-10-28
1
187 Views
Last Modified: 2010-04-01
Given a simple class like:

class Box {
    public:
    int a;
    int b;
};

int main() {
   Box b1;
   Box b2;
}

Are the following two statements effectively the same?  (i.e. do these statements generate the same exact machine code?)

b1 = b2;

memcpy(&b1, &b2, sizeof(Box));
0
Comment
Question by:chsalvia
1 Comment
 
LVL 45

Accepted Solution

by:
sunnycoder earned 125 total points
ID: 17826238
Hi chsalvia,

No ... memcpy would be a call (jump) to a library function. Assignment assembly code would be generated by compiler. Both implementations can be different.

Cheers!
sunnycoder
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question