?
Solved

Shallow copy with no assignment operator

Posted on 2006-10-28
1
Medium Priority
?
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 45

Accepted Solution

by:
sunnycoder earned 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

770 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