CS212: Object Oriented Analysis and Design Lecture 10: Copy constructor-II.

Slides:



Advertisements
Similar presentations
Introduction to Programming Lecture 39. Copy Constructor.
Advertisements

Operator Overloading Fundamentals
CS-1030 Dr. Mark L. Hornick 1 Constructors Copy Constructors.
Object Oriented Programming COP3330 / CGS5409.  C++ Automatics ◦ Copy constructor () ◦ Assignment operator =  Shallow copy vs. Deep copy  DMA Review.
What is a copy constructor? A copy constructor is a special constructor for a class/struct that is used to make a copy of an existing instance during initialization.
Winter 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assn 4 posted shortly. Demonstrate a memory leak problem using the assignment 4 solution. Back to.
Reviews for Exam 1 Chapter 1-4 CSc 212 Data Structures, Sec FG CCNY, Fall 2010.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 13: Pass-by-Value?!?
Reviews for Exam 1 Chapter 1-4 CS 211 Data Structures MHC, 2007.
Dynamically Allocated Arrays May 2, Quiz 5 Today.
Arrays, Pointers and Structures CS-240 Dick Steflik.
C++ data types. Structs vs. Classes C++ Classes.
Copy Constructors Shallow Copy: –The data members of one object are copied into the data members of another object without taking any dynamic memory pointed.
CS 225 Lab #2 - Pointers, Copy Constructors, Destructors, and DDD.
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
1 COMS 261 Computer Science I Title: Classes Date: November 7, 2005 Lecture Number: 28.
Copy Control Joe Meehean. More Class Responsibilities When making a new type (i.e., class) we must specify what happens when it is: Copied Assigned Destroyed.
CS212: Object Oriented Analysis and Design Lecture 12: Operator Overloading-II.
Copy Constructors Fall 2008 Dr. David A. Gaitros
1 Inheritance. 2 Why use inheritance?  The most important aspect of inheritance is that it expresses a relationship between the new class and the base.
Data Structures Using C++1 Chapter 3 Pointers and Array-Based Lists.
Dynamically Allocated Arrays December 4, Skip the Rest of this PowerPoint.
Data Structures Using C++ 2E Chapter 3 Pointers. Data Structures Using C++ 2E2 Objectives Learn about the pointer data type and pointer variables Explore.
Object Oriented Programming Elhanan Borenstein Lecture #3 copyrights © Elhanan Borenstein.
More C++ Features True object initialisation
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
Object-Based Programming Mostly Review. Objects Review what is object? class? member variables? member functions? public members? private members? friend.
CS212: Object Oriented Analysis and Design Lecture 17: Virtual Functions.
CMSC 202, Version 3/02 1 Copy Constructors and Overloaded Assignment.
CSCE Introduction to Program Design and Concepts J. Michael Moore Spring 2015 Set 17: Vectors and Arrays 1 Based on slides created by Bjarne Stroustrup.
OOP in C++ CS 124. Program Structure C++ Program: collection of files Source (.cpp) files be compiled separately to be linked into an executable Files.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Objects and Variables Local variables – Confined to single context: allocated on stack – Primitive types such as int or object references – Must be initialized.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14: More About Classes.
CSE 332: Memory management with C++ classes Memory Management with Classes Review: for non-static built-in (native) types –default constructor and destructor.
1 Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 10 More on Objects and Classes.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 1.
Chapter 1 C++ Basics Review (Section 1.4). Classes Defines the organization of a data user-defined type. Members can be  Data  Functions/Methods Information.
1 // SPECIFICATION FILE (dynarray.h) // Safe integer array class allows run-time specification // of size, prevents indexes from going out of bounds, //
CS212: Object Oriented Analysis and Design Polymorphism (Using C++)
Yan Shi CS/SE 2630 Lecture Notes
Hank Childs, University of Oregon
Class: Special Topics Copy Constructors Static members Friends this
Chapter 1-4 CSc 212 Data Structures, Sec AB CCNY, Spring 2012
Memberwise Assignment / Initialization
This pointer, Dynamic memory allocation, Constructors and Destructor
Automatics, Copy Constructor, and Assignment Operator
Basic C++ What’s a declaration? What’s a definition?
Automatics, Copy Constructor, and Assignment Operator
Dynamic Memory Copy Challenge
Copy Constructor CSCE 121 J. Michael Moore.
Destruction and Copying
Indirection.
Essential Class Operations
Java Programming Language
Destruction and Copying
COP 3330 Object-oriented Programming in C++
Dynamic Memory Copy Challenge
Object oriented programming (OOP) Lecture No. 6
Class: Special Topics 2 For classes using memory allocation
The Constructors Lecture 7 Fri, Feb 2, 2007.
ENERGY 211 / CME 211 Lecture 17 October 29, 2008.
Essential Class Operations
Copy Assignment CSCE 121.
Copy Constructor CSCE 121.
C++ data types.
Rule of Three Part 1 & 2.
C++ support for Object-Oriented Programming
Chapter 1-4 CSc 212 Data Structures, Sec FG CCNY, 2009
Creating and Using Classes
Presentation transcript:

CS212: Object Oriented Analysis and Design Lecture 10: Copy constructor-II

Copy copy: revisited Main Constructor Copy Constructorh f(): global functionx=h

What happens if we don’t use it? Compiler creates one for you in the case of simple structures The default primitive behaviour: a bit-copy. C++ compiler will still automatically create a copy-constructor if you don’t make one The process the compiler goes through to synthesize a copy- constructor is called member-wise initialization.

Issues with pointers 50x A B {B=A;} Initial object Duplicate object

Deep vs Shallow copy Copy constructor is called only for initializations For assignment ? Operator overload ??