Spl - Ps4 - Bgu

Spl - Ps4 - Bgu

SPL PS4 C++ Advanced OOP The rule of 5 The rule of 3 has some problems.

Starting from C++11, two additional functions were added to the rule of 3. Move constructor Move assignment operator Like the rule of 3, implies only for classes that manage resources

The destructor Similar to the destructor weve built in the previous PS The move constructor

Called when an object is initialized from an rvalue reference. Initialization std::string a = str Function argument passing v.push_back(str) Function return by value Steals resources from other object.

The move constructor (cont)

A new charArray object will be created with the given string The move constructor will create a new object inside the vector, and will steal the string The pointer in the first created object will become nullptr

The first object will be destroyed, since its pointer became null, the object on the vector wont be affected. The move assignment operator Similar to the copy assignment operator

Like the move constructor, steals resources from other object Smart pointers Included in the standard library Provides some garbage collection facility

In this practical session well talk about unique pointer Unique pointer Provides limited garbage-collection facility Automatically deletes the pointer they manage, when they are

destroyed or assigned another value. Can also delete the pointer they manage by calling unique_ptr::reset explicitly Owns their pointer uniquely, no other pointer should point to managed object

Unique pointer example C++ Inheritance A relationship among classes, in which one class shares the structure

or functionality of another class. In C++ there are three levels of inheritance visibility C++ Inheritance example

C++ Inheritance example(cont) C++ Inheritance example(cont) C++ Inheritance types

Public Inheritance example isEmpty() is a part of the base class intArray Insert(int,int) is a part of the base class intArray but his functionality is extended in the derived class.

biggest() exists only in the derived class Private inheritance Makes all public and protected methods in base class private in derived class.

Defines a has-a and not a is-a relation between base and derived class. Constructor of derived class The C++ compiler generates a call to the default constructor of the

base class, unless explicitly instructed otherwise. A better solution is to call directly to the CTOR of the base class, using the following syntax

Virtual functions Virtual functions are functions whose behavior can be overridden by derived class. Unlike non-virtual function, overridden behavior is preserved even if no compile-time data is available on the type of the class.

If derived virtual function has a different access level then base function, their access level might not be respected. Virtual function example

Virtual destructor Without garbage collector, polymorphism can be problematic when attempting to release memory. Virtual destructor(cont)

Can be fixed by declaring destructors virtual Pure virtual functions and abstract classes Pure virtual functions dont include implementation in their base

class. Therefore, cannot make instantiation of base class. Namespaces Similar to Java packages.


Recently Viewed Presentations

  • Providing a Custom Abutment System with Must-Have Solutions

    Providing a Custom Abutment System with Must-Have Solutions

    There is also a segment using ball attachments and floating mounts known as Zest Locator system. All developments maintain the EAS core competencies, solving difficult angles, fixing loose screws and easily retrievable.
  • 投影片 1 - Ntnu

    投影片 1 - Ntnu

    TK w1 w2 wj wm D1 D2 Di Dn IR - Berlin Chen * PLSA: One more example on TDT1 dataset aviation space missions family love Hollywood love IR - Berlin Chen * PLSA: Experiment Results (1/4) Experimental Results Two...
  • What is International Business?

    What is International Business?

    2nd Edition Michael R. Czinkota and Masaaki Kotabe Chapter 11: Distribution and Supply Chain Management Chapter Outline Distribution channel Channel compensation Channel membership Channel integration Retailing Wholesaling Purchasing The supply chain Supply chain management Customer service Distribution Channel Member organizations...
  • CSC401: Analysis of Algorithms

    CSC401: Analysis of Algorithms

    Asymptotic notion of algorithm efficiency What is an algorithm ? Running Time Most algorithms transform input objects into output objects. The running time of an algorithm typically grows with the input size. Average case time is often difficult to determine....
  • Differential Calculus - Ms Gugger's Classes 2016

    Differential Calculus - Ms Gugger's Classes 2016

    At point of inflection, the tangent will pass through the curve, and the curve will change from concave down to concave up or vice versa on either side of the point of inflection. ... It is positioned so that its...
  • Short Food Chains and Local Food Systems: An

    Short Food Chains and Local Food Systems: An

    CPRE (2012)Mapping Local Food Webs National Report. Kneafsey, M. et al (2013) Short Food Supply Chains and Local Food Systems in the EU: A State of Play - available on request. New Economics Foundation (2011) The Benefits of Procuring School...
  • Congestive heart failure Dr. Jamal Dabbas Interventional cardiologist

    Congestive heart failure Dr. Jamal Dabbas Interventional cardiologist

    NYHA class. Characteristics. Class I. No limitations of physical activity; no symptoms of CHF. Class II. Slight limitations of moderate or prolonged physical activity (e.g., sympt
  • www.marcreed.com


    150 Years of Movement Toward Community in the United States James W. Conroy, Ph.D. The Center for Outcome Analysis www.eoutcome.org What is the Purpose of Human Services? "Are p