Solved

Shallow copy with no assignment operator

Posted on 2006-10-28
1
184 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now