C++ Programming: Polymorphism

Size: px
Start display at page:

Download "C++ Programming: Polymorphism"

Transcription

1 C++ Programming: Polymorphism 2018 년도 2 학기 Instructor: Young-guk Ha Dept. of Computer Science & Engineering

2 Contents Run-time binding in C++ Abstract base classes Run-time type identification 2

3 Function Binding in C++ Function binding To associate a function s name with its entry point, which is the starting address of the code that implements the function Types of function binding in C++ Compile-time binding To bind any invocation of a function to its entry point when the program is being compiled I.e., compiler determines what code is to be executed Has been in effect throughout our examples so far Run-time binding The alternative of the compile-time binding To bind a function when the program is running 3

4 Polymorphism Polymorphism is run-time binding of methods I.e., a method is polymorphic if its binding occurs at run-time rather than compile-time A powerful tool for programmers A programmer can invoke an object s polymorphic method without knowing exactly which class type or subtype is involved E.g., a Window class hierarchy Imagine a base class Window and its 20 or so derived classes Each class has a polymorphic display method with the same signature, which performs some class-specific operation The programmer needs to remember only one method signature to invoke 20 or so different methods 4

5 Example of Polymorphism Various versions of the display method Base class Window has a display method to draw basic window frames on the screen MenuWindow has a display to show a list of choices in addition Each Window class has its own version of display method A client can invoke a single display method for any type of Window at runtime E.g., w->display(); If w points to a Window object, its display is invoked Else if w points to a MenuWindow or DialogWindow object, each display is invoked Window* w Window ::display() MenuWindow DialogWindow ::display() ::display() Note that what version of display to be invoked is determined at runtime (not compile time) InformationDialog ::display() 5

6 Requirements for C++ Polymorphism Three requirements for implementation of polymorphism in C++ 1) When defining classes with polymorphic methods All the classes must be in the same inheritance hierarchy 2) When defining polymorphic methods The methods must be virtual and have the same signature 3) When using polymorphic methods There must be a pointer of base class, which is used to invoke the virtual methods No cast is required when assigning a pointer of base class to an object of derived class (* note that a pointer of base class may point to an object of any derived class) 6

7 Polymorphism Example // base class class TradesPerson { virtual void sayhi() { cout << Just hi. << endl; } // derived class 1 class Tinker : public TradesPerson { virtual void sayhi() { cout << Hi, I tinker. << endl; } // derived class 2 class Tailor : public TradesPerson { virtual void sayhi() { cout << Hi, I tailor. << endl; } int main() { // pointer to base class TradesPerson* p; int which; do { cout << 1 == TradesPerson, << 2 == Tinker, 3 == Tailor ; cin >> which; } while (which < 1 which > 3); } // set p depending on user choice switch (which) { case 1: p = new TradesPerson; break; case 2: p = new Tinker; break; case 3: p = new Tailor; break; } // run-time binding in effect p->sayhi(); delete p; // free the storage 7

8 Polymorphism Example (cont.) TradesPerson Object virtual void sayhi(); TradesPerson TradesPerson *p p->sayhi(); Just hi. Tinker Tailor Tinker Object virtual void sayhi(); Tailor Object virtual void sayhi(); *p p->sayhi(); Hi, I tinker. *p p->sayhi(); Hi, I tailor. 8

9 Implicit virtual Methods Using keyword virtual in all the polymorphic methods is not a requirement If a base class method is declared virtual, any derived class method with the same signature is automatically declared virtual, even if not explicitly declared E.g., in the previous example, keyword virtual in front of method Tinker::sayHi can be omitted class TradesPerson { virtual void sayhi() { cout << "Just hi." << endl; } class Tinker : public TradesPerson { void sayhi() { cout << "Hi, I tinker." << endl; }... 9

10 Notices on Using Keyword virtual In case of defining a virtual method outside the class, the keyword virtual occurs only in the method s declaration, not in its definition class C { virtual void m(); // declaration: "virtual" occurs... void C::m() {... } // definition: no "virtual" Top-level functions can not be virtual, only methods can be virtual virtual void f(); int main() {... } // ERROR: not a method! 10

11 Inheriting virtual Methods virtual methods can be inherited from base classes to derived classes just like common methods E.g., class Tinker does not provide its own definition of sayhi, it inherits sayhi from its base class TradesPerson class TradesPerson { virtual void sayhi(){ cout << "Just hi." << endl; } class Tinker : public TradesPerson {... // no Tinker s sayhi defined int main() { Tinker t1; t1.sayhi();... } // inherited TradesPerson s sayhi Just hi. 11

12 The Vtable OOP languages commonly use the vtable (virtual table) to implement run-time binding Implementation of vtable is system-dependent The purpose of vtable is to support run-time lookup of a particular entry point for a function s name Thus, a program using run-time binding incurs performance penalty due to vtable lookup Space: amount of storage for the vtable Time: time taken for vtable lookup E.g., Smalltalk vs. C++ In a pure OOP language such as Smalltalk, all methods are polymorphic by default suffers from heavy performance penalty In C++, programmer can choose polymorphic (virtual) methods smaller performance penalty 12

13 Vtable Example class B { // base class virtual void m1() {... } virtual void m2() {... } class D : public B { // derived class virtual void m2() {... } int main() { B b; // base class object D d; // derived class object B* p; // pointer to base class virtual Method Name b.m1 b.m2 d.m2 [ Vtable ] Entry Point 0x7723 0x23b4 0x99a7 } p = &b; // p is set to b s address p->m2(); // vtable lookup for run-time binding p = &d; // p is set to d s address p->m2(); // vtable lookup for run-time binding 13

14 Constructors and Destructors A constructor can NOT be virtual, but a destructor CAN be virtual class C { virtual C(); virtual C(int a); virtual ~C(); virtual void m(); // ERROR: a constructor // ERROR: a constructor // OK: a destructor // OK: a regular method 14

15 virtual Destructors In some cases, destructors should be made virtual to ensure that polymorphism is at work for the destructors of the derived classes E.g., if a derived class has a data member that points to dynamically allocated storage and the destructor to free such storage storage leakage problem can occur when handling the derived class with a pointer to its base class (refer to the next example) In commercial libraries (e.g., MFC), destructors are typically virtual to prevent such problem 15

16 virtual Destructors Example Example codes of the storage leakage problem class A { A() { p = new char[5]; } ~A() { }... delete[] p; // free p class Z : public A { Z() { q = new char[5000]; } ~Z() { }... delete[] q; // free q void f() { A* ptr; // type of ptr is pointer // of the base class A ptr = new Z(); // both A() and Z() fire // a Z object is created delete ptr; // only ~A() fires, not ~Z() // no polymorphism // (ptr is a pointer of // class A) } // Caution: results in 5,000 bytes // of leaked storage 16

17 virtual Destructors Example (cont.) The previous problem can be fixed by making the destructors virtual By making the base class destructor ~A() virtual, we can make derived class destructor ~Z() virtual implicitly class A {... virtual ~A() { delete[ ] p; }... // virtual destructor // ~Z() becomes virtual as well void f() {... delete ptr; // ~Z() fires and then ~A() fires // checks what ptr actually points to,... // not the type of ptr } A() firing Z() firing ~Z() firing ~A() firing 17

18 Class Methods and Run-Time Biding static methods (class methods) can not be virtual class C { // ERROR: static and virtual static virtual void f(); static void g(); // OK, not virtual virtual void h(); // OK, not static 18

19 Other C++ Constructs That Resembles Run-Time Binding In C++, only virtual methods are bound at run-time Only virtual methods are truly polymorphic C++ has some other constructs that resemble runtime binding but are quite distinct from it (actually, compile-time binding) Name overloading (both methods and functions) Name overriding Name hiding 19

20 Name Overloading When top-level functions or methods in the same class share one name, but have different signatures class C { C() {... } // default constructor C(int x) {... } // convert constructor void f(double d) {... } void f(char C) {... } int main() { C c1; C c2(26); f(3.14); f('z ); } // default constructor called // convert constructor called // f(double) is bound by compiler // f(char) is bound by compiler 20

21 Name Overriding When a base class and its derived class have methods with the same signature (not declared virtual) class B { // base class void m() { cout << "B::m" << endl; } // m is not virtual class D : public B { // derived class void m() { cout << "D::m" << endl; } // overrides B::m int main() { } D q; q.m(); B* p; p = &q; p->m(); // invokes D::m // (D::m overrides B::m) // invokes B::m (not D::m) // if B::m is declared virtual class B { // base class virtual void m() { cout << "B::m" << endl; }... int main() { }... B* p; p = &q; p->m(); // invokes D::m // (polymorphism) 21

22 Name Hiding When a base class and its derived class have methods with the same name and different signatures class B { void m(int x) { cout << x << endl; } class D : public B { void m() { cout << "Hi" << endl; } int main() { D d; d.m(); // OK d.m(26); // Error: B s m(int) is hidden by D s m() // to correct, use d1.b::m(26) return 0; } 22

23 Name Sharings in C++ Run time binding Polymorphism Between virtual methods of classes in the same hierarchy Have the same signature Name overriding Between methods (not virtual) of classes in the same hierarchy Have the same signature Compile time binding Name hiding Between methods (not virtual) of classes in the same hierarchy Have the same name but different signatures Name overloading Between methods in the same class or top-level functions Have the same name but different signatures 23

24 Another Usage of virtual: Shared Interfaces In OO design, sometimes, it is required that different classes must commonly define a collection of specific methods It is called shared interface (cf. interface in Java) E.g., a Window class hierarchy designer may want to ensure that each derived class in the hierarchy defines its own display, close, and move methods We can use a kind of virtual methods to enforce derived classes to define (override) those methods Note that generic virtual methods could be, but need not be overridden in derived classes class B { // base class virtual void m() {... } class D : public B { // derived class //... no m() is defined in D // thus B::m is just inherited (need not be overridden) 24

25 Pure virtual Methods Pure virtual methods Methods that any derived classes must override in order to instantiate their objects Declarations end with the special syntax =0 Have no definitions // a class with pure virtual methods class ABC { virtual void open() = 0; virtual void close() = 0; virtual void flush() = 0; 25

26 Abstract Base Classes What is an abstract base class (ABC) A class that has one of more pure virtual methods Just one pure virtual method suffices to make a class abstract ABCs can NOT instantiate their objects because they are abstract ABC is typically used as a shared interface in C++ class ABC { // Abstract Base Class virtual void open() = 0;... ABC obj; // ERROR: ABC is an abstract class 26

27 ABC and Derived Classes Although an ABC can not have any object that instantiates it, it can have derived classes Classes derived from an ABC MUST override all of the ABC s pure virtual methods Otherwise, the derived classes also become abstract and no objects can instantiate them class ABC { // Abstract Base Class virtual void open() = 0; class X : public ABC { // 1st derived class virtual void open() {... } // overrides open() class Y : public ABC { // 2nd derived class // *** open is not overridden ABC a1; // *** ERROR: ABC is abstract X x1; // *** OK, X overrides open() and is not abstract Y y1; // *** ERROR: Y is also abstract open() is not defined 27

28 ABC and Other Members ABCs may have other members than pure virtual methods, which can be normally inherited Data members Constructors and destructors Ordinary methods and virtual methods class ABC { // Abstract Base Class ABC() {... } ABC(int x) {... } ~ABC() {... } virtual void open() = 0; virtual void print() const {... } int getcount() const { return n; } private: int n; // constructor // constructor // destructor // pure virtual // virtual // nonvirtual // data member 28

29 Restriction on Pure Declarations Only virtual methods can be pure Neither nonvirtual methods nor top-level functions can be declared pure void f() = 0; // **** ERROR: not a method class C { void open() = 0; // **** ERROR: not virtual... 29

30 Usage of ABC (1) class IFile { // file interface virtual void open() = 0; virtual void close() = 0; virtual void flush() = 0; class TextFile : public IFile { virtual void open() {... } virtual void close() {... } virtual void flush() {... } class BinaryFile : public IFile { virtual void open() {... } virtual void close() {... } virtual void flush() {... } // to open a text file // to close a text file // to flush a text file // to open a binary file // to close a binary file // to flush a binary file 30

31 Usage of ABC (2) To specify program design requirements E.g., introspection methods for a big project A large number of programmers: each programmer is responsible for a number of classes During the design phase, the PM decided that each class should have two public methods to introspect the class Such design decision can be enforced by using an ABC class IIntrospect { // introspection interface virtual void listdata() = 0; // prints data members info. virtual void listmethods() = 0; // prints methods info. } 31

32 Run-Time Type Identification C++ supports run-time type identification, which provides mechanisms To check if type conversion is safe at run time Using dynamic_cast operator To determine type of object or class at run time Using typeid operator 32

33 Dynamic Cast Previously discussed cast operators in C++ static_cast Can be applied to any type (polymorphic or not) E.g., Converting int a to float b b = static_cast<float>(a) == b = (float)a Static cast (at compile-time) does not ensure type safety at run-time const_cast Used to cast away constness of a pointer to a const object reinterpret_cast Used to convert from a pointer of one type to a pointer of another type dynamic_cast The dynamic cast operator tests at run-time whether a cast involving objects is type safe or not 33

34 Type Safety Problem of static_cast at Run-Time A derived class pointer actually points to a base class object class B { virtual void f() {... } // note: no method m class D : public B { void m() {... } // additional method m of class D int main() { D* p; // pointer to derived class p = new B; // compile-time error: cast required p = static_cast<d*>(new B); // legal but dealt w/ caution p->m(); // run-time error: even though p is a pointer of D // it actually points to a B object 34

35 Type Safety Problem Illustrated D* p; X B_Object D* p; D_Object D* p; D_Object void f(); void f(); void m(); void f(); void m(); static_cast<d*>(&b_object) B_Object p->m(); void f(); 35

36 dynamic_cast to Resolve Type Safety Problem C++ provides dynamic_cast operator to check at run-time whether a cast is type safe or not dynamic_cast<target_type_ptr>(source_obj_ptr) Evaluates to target_obj_ptr (true), if the cast is type safe Evaluates to 0 (NULL or false), if the cast is not type safe Notices on using dynamic_cast A dynamic_cast is legal only for polymorphic types The source type (type of source_obj_ptr) must have a virtual method The target type and the source type must be on the same inheritance hierarchy Target type must be specified as a pointer or a reference dynamic_cast<t>(ptr) Error Dynamic_cast<T*>(ptr) OK 36

37 dynamic_cast Example class B { virtual void f() {... } class D : public B { void m() {... } Error: not safe int main() { D* p; // pointer to derived class p = dynamic_cast<d*>(new B); if (p) p->m(); // if type safe then invoke p->m() else cerr << Error: not safe << endl; 37

38 Checking Parameter s Type at Run-Time with dynamic_cast virtual void printtitle() class Book class Fiction virtual void printtitle() class Textbook virtual void printtitle() void printlevel() void printbookinfo(book* bookptr) invokes bookptr->printtitle() invokes bookptr->printlevel() not safe 38

39 Checking Parameter s Type at Run- Time with dynamic_cast (cont.) class Book { virtual void printtitle() const {... }... } class Textbook : public Book { void printtitle() const {... } void printlevel() const {... }... } class Fiction : public Book { void printtitle() const {... }... } void printbookinfo(book* bookptr) { bookptr->printtitle(); // print title in any case Textbook* ptr = dynamic_cast<textbook*>(bookptr); if (ptr) ptr->printlevel(); // invoke printlevel if type safe } 39

40 downcast upcast The Rules for dynamic_cast Simple rules for dynamic_cast dynamic_cast from a directly or indirectly derived type to a base type succeeds (upcast) E.g., dynamic_cast<b*>(new D1) will succeed dynamic_cast from a base type to a directly or indirectly derived type may fail (downcast) E.g., dynamic_cast<d1*>(new B) may fail dynamic_cast between unrelated types (other than void) fails E.g., dynamic_cast<d1*>(new Z) or vice versa will fail B Z D1 : success D2 D3 : fail : may fail 40

41 Run-Time Type Determination with the typeid Operator The typeid operator is used to determine an expression s type at run-time typeid(typename expression) Returns a reference to a type_info object that represents the given typename or expression typeinfo header needs to be included first E.g., given float x and long val typeid Statement typeid( x ) == typeid( float ) typeid( x ) == typeid( double ) typeid( x ) == typeid( float* ) typeid( val ) == typeid( long ) typeid( val ) == typeid( short ) typeid( 5280 ) == typeid( int ) typeid( E-9L ) == typeid( long double ) Evaluation true false false true false true true 41

42 Run-Time Type Determination with the typeid Operator (cont.) E.g., given the previous Book class hierarchy and the following declaration Book* bookptr = new Textbook( test, 1); typeid Statement Evaluation typeid( bookptr ) == typeid( Book* ) typeid( bookptr ) == typeid( Textbook* ) typeid( *bookptr ) == typeid( Book ) typeid( *bookptr ) == typeid( Textbook ) true false false true 42

POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors

POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors CSC 330 OO Software Design 1 Abstract Base Classes class B { // base class virtual void m( ) =0; // pure virtual

More information

POLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE

POLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE Abstract Base Classes POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors class B { // base class virtual void m( ) =0; // pure virtual function class D1 : public

More information

Polymorphism. Zimmer CSCI 330

Polymorphism. Zimmer CSCI 330 Polymorphism Polymorphism - is the property of OOP that allows the run-time binding of a function's name to the code that implements the function. (Run-time binding to the starting address of the code.)

More information

What is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1

What is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1 Polymorphism Part 1 What is Polymorphism? Polymorphism refers to a programming language s ability to process objects differently depending on their data type or class. Number person real complex kid adult

More information

Polymorphism Part 1 1

Polymorphism Part 1 1 Polymorphism Part 1 1 What is Polymorphism? Polymorphism refers to a programming language s ability to process objects differently depending on their data type or class. Number person real complex kid

More information

Polymorphism. Miri Ben-Nissan (Kopel) Miri Kopel, Bar-Ilan University

Polymorphism. Miri Ben-Nissan (Kopel) Miri Kopel, Bar-Ilan University Polymorphism Miri Ben-Nissan (Kopel) 1 Shape Triangle Rectangle Circle int main( ) Shape* p = GetShape( ); p->draw( ); Shape* GetShape( ) choose randomly which shape to send back For example: Shape* p

More information

Increases Program Structure which results in greater reliability. Polymorphism

Increases Program Structure which results in greater reliability. Polymorphism UNIT 4 C++ Inheritance What is Inheritance? Inheritance is the process by which new classes called derived classes are created from existing classes called base classes. The derived classes have all the

More information

VIRTUAL FUNCTIONS Chapter 10

VIRTUAL FUNCTIONS Chapter 10 1 VIRTUAL FUNCTIONS Chapter 10 OBJECTIVES Polymorphism in C++ Pointers to derived classes Important point on inheritance Introduction to virtual functions Virtual destructors More about virtual functions

More information

C++ Crash Kurs. Polymorphism. Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck

C++ Crash Kurs. Polymorphism. Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck C++ Crash Kurs Polymorphism Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck http://www.itm.uni-luebeck.de/people/pfisterer C++ Polymorphism Major abstractions of C++ Data abstraction

More information

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

Cpt S 122 Data Structures. Course Review Midterm Exam # 2 Cpt S 122 Data Structures Course Review Midterm Exam # 2 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 2 When: Monday (11/05) 12:10 pm -1pm

More information

OBJECT ORIENTED PROGRAMMING USING C++

OBJECT ORIENTED PROGRAMMING USING C++ OBJECT ORIENTED PROGRAMMING USING C++ Overview of C++ Overloading Overloading occurs when the same operator or function name is used with different signatures Both operators and functions can be overloaded

More information

Inclusion Polymorphism

Inclusion Polymorphism 06D-1 Inclusion Polymorphism Polymorphic code Polymorphic references Up- and Down- Casting Polymorphism and values Polymorphic Arrays Inclusion Polymorphism in Context 06D-2 Polymorphism Ad hoc Universal

More information

QUIZ. Write the following for the class Bar: Default constructor Constructor Copy-constructor Overloaded assignment oper. Is a destructor needed?

QUIZ. Write the following for the class Bar: Default constructor Constructor Copy-constructor Overloaded assignment oper. Is a destructor needed? QUIZ Write the following for the class Bar: Default constructor Constructor Copy-constructor Overloaded assignment oper. Is a destructor needed? Or Foo(x), depending on how we want the initialization

More information

Intro to OOP Visibility/protection levels and constructors Friend, convert constructor, destructor Operator overloading a<=b a.

Intro to OOP Visibility/protection levels and constructors Friend, convert constructor, destructor Operator overloading a<=b a. Intro to OOP - Object and class - The sequence to define and use a class in a program - How/when to use scope resolution operator - How/when to the dot operator - Should be able to write the prototype

More information

Inheritance, Polymorphism and the Object Memory Model

Inheritance, Polymorphism and the Object Memory Model Inheritance, Polymorphism and the Object Memory Model 1 how objects are stored in memory at runtime? compiler - operations such as access to a member of an object are compiled runtime - implementation

More information

Tokens, Expressions and Control Structures

Tokens, Expressions and Control Structures 3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type

More information

C++ Programming: Introduction to C++ and OOP (Object Oriented Programming)

C++ Programming: Introduction to C++ and OOP (Object Oriented Programming) C++ Programming: Introduction to C++ and OOP (Object Oriented Programming) 2018 년도 2 학기 Instructor: Young-guk Ha Dept. of Computer Science & Engineering Contents Brief introduction to C++ OOP vs. Procedural

More information

Dynamic Binding C++ Douglas C. Schmidt

Dynamic Binding C++ Douglas C. Schmidt Dynamic Binding C++ Douglas C. Schmidt Professor Department of EECS d.schmidt@vanderbilt.edu Vanderbilt University www.dre.vanderbilt.edu/schmidt/ (615) 343-8197 Motivation When designing a system it is

More information

Data Abstraction. Hwansoo Han

Data Abstraction. Hwansoo Han Data Abstraction Hwansoo Han Data Abstraction Data abstraction s roots can be found in Simula67 An abstract data type (ADT) is defined In terms of the operations that it supports (i.e., that can be performed

More information

Strict Inheritance. Object-Oriented Programming Spring 2008

Strict Inheritance. Object-Oriented Programming Spring 2008 Strict Inheritance Object-Oriented Programming 236703 Spring 2008 1 Varieties of Polymorphism P o l y m o r p h i s m A d h o c U n i v e r s a l C o e r c i o n O v e r l o a d i n g I n c l u s i o n

More information

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II Inheritance Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

More information

(12-1) OOP: Polymorphism in C++ D & D Chapter 12. Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University

(12-1) OOP: Polymorphism in C++ D & D Chapter 12. Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University (12-1) OOP: Polymorphism in C++ D & D Chapter 12 Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University Key Concepts Polymorphism virtual functions Virtual function tables

More information

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++

More information

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II Inheritance Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

More information

Strict Inheritance. Object-Oriented Programming Winter

Strict Inheritance. Object-Oriented Programming Winter Strict Inheritance Object-Oriented Programming 236703 Winter 2014-5 1 1 Abstractions Reminder A class is an abstraction over objects A class hierarchy is an abstraction over classes Similar parts of different

More information

Fast Introduction to Object Oriented Programming and C++

Fast Introduction to Object Oriented Programming and C++ Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming

More information

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1 Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1 Inheritance Consider a new type Square. Following how we declarations for the Rectangle and Circle classes we could declare it as follows:

More information

Where do we stand on inheritance?

Where do we stand on inheritance? In C++: Where do we stand on inheritance? Classes can be derived from other classes Basic Info about inheritance: To declare a derived class: class :public

More information

Dr. Md. Humayun Kabir CSE Department, BUET

Dr. Md. Humayun Kabir CSE Department, BUET C++ Type Casting Dr. Md. Humayun Kabir CSE Department, BUET C++ Type Casting Converting a value of a given type into another type is known as type-casting. ti Conversion can be implicit or explicit 2 C++

More information

04-24/26 Discussion Notes

04-24/26 Discussion Notes 04-24/26 Discussion Notes PIC 10B Spring 2018 1 When const references should be used and should not be used 1.1 Parameters to constructors We ve already seen code like the following 1 int add10 ( int x

More information

COMP322 - Introduction to C++ Lecture 09 - Inheritance continued

COMP322 - Introduction to C++ Lecture 09 - Inheritance continued COMP322 - Introduction to C++ Lecture 09 - Inheritance continued Dan Pomerantz School of Computer Science 11 March 2012 Recall from last time Inheritance describes the creation of derived classes from

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED

엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED 엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED - Polymorphism - Virtual Functions - Abstract Classes - Virtual

More information

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,

More information

Polymorphism. Contents. Assignment to Derived Class Object. Assignment to Base Class Object

Polymorphism. Contents. Assignment to Derived Class Object. Assignment to Base Class Object Polymorphism C++ Object Oriented Programming Pei-yih Ting NTOU CS 26-1 Contents Assignment to base / derived types of objects Assignment to base / derived types of pointers Heterogeneous container and

More information

Object Oriented Programming. Solved MCQs - Part 2

Object Oriented Programming. Solved MCQs - Part 2 Object Oriented Programming Solved MCQs - Part 2 Object Oriented Programming Solved MCQs - Part 2 It is possible to declare as a friend A member function A global function A class All of the above What

More information

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University)

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University) Estd: 1994 JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli - 621014 (An approved by AICTE and Affiliated to Anna University) ISO 9001:2000 Certified Subject Code & Name : CS 1202

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

Chapter 5 Object-Oriented Programming

Chapter 5 Object-Oriented Programming Chapter 5 Object-Oriented Programming Develop code that implements tight encapsulation, loose coupling, and high cohesion Develop code that demonstrates the use of polymorphism Develop code that declares

More information

Note 12/1/ Review of Inheritance Practice: Please write down 10 most important facts you know about inheritance...

Note 12/1/ Review of Inheritance Practice: Please write down 10 most important facts you know about inheritance... CISC 2000 Computer Science II Fall, 2014 Note 12/1/2014 1 Review of Inheritance Practice: Please write down 10 most important facts you know about inheritance... (a) What s the purpose of inheritance?

More information

C++ without Classes. CMSC433, Fall 2001 Programming Language Technology and Paradigms. More C++ without Classes. Project 1. new/delete.

C++ without Classes. CMSC433, Fall 2001 Programming Language Technology and Paradigms. More C++ without Classes. Project 1. new/delete. CMSC433, Fall 2001 Programming Language Technology and Paradigms Adam Porter Sept. 4, 2001 C++ without Classes Don t need to say struct New libraries function overloading confusing link messages default

More information

15: Polymorphism & Virtual Functions

15: Polymorphism & Virtual Functions 15: Polymorphism & Virtual Functions 김동원 2003.02.19 Overview virtual function & constructors Destructors and virtual destructors Operator overloading Downcasting Thinking in C++ Page 1 virtual functions

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

CS105 C++ Lecture 7. More on Classes, Inheritance

CS105 C++ Lecture 7. More on Classes, Inheritance CS105 C++ Lecture 7 More on Classes, Inheritance " Operator Overloading Global vs Member Functions Difference: member functions already have this as an argument implicitly, global has to take another parameter.

More information

These new operators are intended to remove some of the holes in the C type system introduced by the old C-style casts.

These new operators are intended to remove some of the holes in the C type system introduced by the old C-style casts. asting in C++: Bringing Safety and Smartness to Your Programs of 10 10/5/2009 1:20 PM By G. Bowden Wise The new C++ standard is full of powerful additions to the language: templates, run-time type identification

More information

ECE 3574: Dynamic Polymorphism using Inheritance

ECE 3574: Dynamic Polymorphism using Inheritance 1 ECE 3574: Dynamic Polymorphism using Inheritance Changwoo Min 2 Administrivia Survey on class will be out tonight or tomorrow night Please, let me share your idea to improve the class! 3 Meeting 10:

More information

What is Inheritance?

What is Inheritance? Inheritance 1 Agenda What is and Why Inheritance? How to derive a sub-class? Object class Constructor calling chain super keyword Overriding methods (most important) Hiding methods Hiding fields Type casting

More information

Practice for Chapter 11

Practice for Chapter 11 Practice for Chapter 11 MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Object-oriented programming allows you to derive new classes from existing

More information

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass

More information

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am CMSC 202 Section 010x Spring 2007 Computer Science II Final Exam Name: Username: Score Max Section: (check one) 0101 - Justin Martineau, Tuesday 11:30am 0102 - Sandeep Balijepalli, Thursday 11:30am 0103

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 12 Thomas Wies New York University Review Last lecture Modules Outline Classes Encapsulation and Inheritance Initialization and Finalization Dynamic

More information

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT Two Mark Questions UNIT - I 1. DEFINE ENCAPSULATION. Encapsulation is the process of combining data and functions

More information

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

Design issues for objectoriented. languages. Objects-only pure language vs mixed. Are subclasses subtypes of the superclass? Encapsulation Encapsulation grouping of subprograms and the data they manipulate Information hiding abstract data types type definition is hidden from the user variables of the type can be declared variables

More information

CMSC 132: Object-Oriented Programming II

CMSC 132: Object-Oriented Programming II CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation

More information

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1 Object-Oriented Languages and Object-Oriented Design Ghezzi&Jazayeri: OO Languages 1 What is an OO language? In Ada and Modula 2 one can define objects encapsulate a data structure and relevant operations

More information

Inheritance & Polymorphism. Object-Oriented Programming Spring 2015

Inheritance & Polymorphism. Object-Oriented Programming Spring 2015 Inheritance & Polymorphism Object-Oriented Programming 236703 Spring 2015 1 1 Abstractions Reminder A class is an abstraction over objects A class hierarchy is an abstraction over classes Similar parts

More information

OOP THROUGH C++(R16) int *x; float *f; char *c;

OOP THROUGH C++(R16) int *x; float *f; char *c; What is pointer and how to declare it? Write the features of pointers? A pointer is a memory variable that stores the address of another variable. Pointer can have any name that is legal for other variables,

More information

C++ Casts and Run-Time Type Identification

C++ Casts and Run-Time Type Identification APPENDIX K C++ Casts and Run-Time Type Identification Introduction There are many times when a programmer needs to use type casts to tell the compiler to convert the type of an expression to another type.

More information

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in

More information

PIC 10A Pointers, Arrays, and Dynamic Memory Allocation. Ernest Ryu UCLA Mathematics

PIC 10A Pointers, Arrays, and Dynamic Memory Allocation. Ernest Ryu UCLA Mathematics PIC 10A Pointers, Arrays, and Dynamic Memory Allocation Ernest Ryu UCLA Mathematics Pointers A variable is stored somewhere in memory. The address-of operator & returns the memory address of the variable.

More information

Preface to the Second Edition Preface to the First Edition Brief Contents Introduction to C++ p. 1 A Review of Structures p.

Preface to the Second Edition Preface to the First Edition Brief Contents Introduction to C++ p. 1 A Review of Structures p. Preface to the Second Edition p. iii Preface to the First Edition p. vi Brief Contents p. ix Introduction to C++ p. 1 A Review of Structures p. 1 The Need for Structures p. 1 Creating a New Data Type Using

More information

CPS 506 Comparative Programming Languages. Programming Language

CPS 506 Comparative Programming Languages. Programming Language CPS 506 Comparative Programming Languages Object-Oriented Oriented Programming Language Paradigm Introduction Topics Object-Oriented Programming Design Issues for Object-Oriented Oriented Languages Support

More information

Introduction to RTTI. Jonathan Hoyle Eastman Kodak 11/30/00

Introduction to RTTI. Jonathan Hoyle Eastman Kodak 11/30/00 Introduction to RTTI Jonathan Hoyle Eastman Kodak 11/30/00 Overview What is RTTI? typeid( ) function Polymorphism dynamic_cast< > operation RTTI Gotcha s Demo What is RTTI? Run-Time Type Identification

More information

Concepts of Programming Languages

Concepts of Programming Languages Concepts of Programming Languages Lecture 10 - Object-Oriented Programming Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages

More information

Chapter 2. Procedural Programming

Chapter 2. Procedural Programming Chapter 2 Procedural Programming 2: Preview Basic concepts that are similar in both Java and C++, including: standard data types control structures I/O functions Dynamic memory management, and some basic

More information

Programming C++ Lecture 5. Howest, Fall 2013 Instructor: Dr. Jennifer B. Sartor

Programming C++ Lecture 5. Howest, Fall 2013 Instructor: Dr. Jennifer B. Sartor Programming C++ Lecture 5 Howest, Fall 2013 Instructor: Dr. Jennifer B. Sartor Jennifer.sartor@elis.ugent.be S Templates S Function and class templates you specify with a single code segment an entire

More information

Instantiation of Template class

Instantiation of Template class Class Templates Templates are like advanced macros. They are useful for building new classes that depend on already existing user defined classes or built-in types. Example: stack of int or stack of double

More information

A <Basic> C++ Course

A <Basic> C++ Course adapted from Jean-Paul Rigault courses 1 A C++ Course 8 Object-oriented programming 2 Julien Deantoni 2 Outline Dynamic Typing Truncature Cast 3 Variants of class Paragraph Definition of derived

More information

Variables. Data Types.

Variables. Data Types. Variables. Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable. We had to write several lines of code, compile them, and then execute the resulting

More information

Data type of a pointer must be same as the data type of the variable to which the pointer variable is pointing. Here are a few examples:

Data type of a pointer must be same as the data type of the variable to which the pointer variable is pointing. Here are a few examples: Unit IV Pointers and Polymorphism in C++ Concepts of Pointer: A pointer is a variable that holds a memory address of another variable where a value lives. A pointer is declared using the * operator before

More information

Inheritance, and Polymorphism.

Inheritance, and Polymorphism. Inheritance and Polymorphism by Yukong Zhang Object-oriented programming languages are the most widely used modern programming languages. They model programming based on objects which are very close to

More information

CS11 Advanced C++ Fall Lecture 7

CS11 Advanced C++ Fall Lecture 7 CS11 Advanced C++ Fall 2006-2007 Lecture 7 Today s Topics Explicit casting in C++ mutable keyword and const Template specialization Template subclassing Explicit Casts in C and C++ C has one explicit cast

More information

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs. Local Variable Initialization Unlike instance vars, local vars must be initialized before they can be used. Eg. void mymethod() { int foo = 42; int bar; bar = bar + 1; //compile error bar = 99; bar = bar

More information

W3101: Programming Languages C++ Ramana Isukapalli

W3101: Programming Languages C++ Ramana Isukapalli Lecture-6 Operator overloading Namespaces Standard template library vector List Map Set Casting in C++ Operator Overloading Operator overloading On two objects of the same class, can we perform typical

More information

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++ Introduction to Programming in C++ Course Text Programming in C++, Zyante, Fall 2013 edition. Course book provided along with the course. Course Description This course introduces programming in C++ and

More information

Extending Classes (contd.) (Chapter 15) Questions:

Extending Classes (contd.) (Chapter 15) Questions: Extending Classes (contd.) (Chapter 15) Questions: 1 Virtual Functions in C++ Employee /\ / \ ---- Manager 2 Case 1: class Employee { string firstname, lastname; //... Employee( string fnam, string lnam

More information

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. OOPs Concepts 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. Type Casting Let us discuss them in detail: 1. Data Hiding: Every

More information

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

More information

Making Inheritance Work: C++ Issues

Making Inheritance Work: C++ Issues Steven Zeil September 19, 2013 Contents 1 Base Class Function Members 2 2 Assignment and Subtyping 3 3 Virtual Destructors 5 4 Virtual Assignment 9 5 Virtual constructors 11 51 Cloning 13 6 Downcasting

More information

Making Inheritance Work: C++ Issues

Making Inheritance Work: C++ Issues Steven Zeil September 19, 2013 Contents 1 Base Class Function Members 2 2 Assignment and Subtyping 3 3 Virtual Destructors 4 4 Virtual Assignment 7 5 Virtual constructors 9 51 Cloning 11 6 Downcasting

More information

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved. C How to Program, 6/e 1992-2010 by Pearson Education, Inc. All Rights Reserved. 1 Standard Behavior: When the compiler is working out which member function to call, it selects according to the type of

More information

C++ Inheritance II, Casting

C++ Inheritance II, Casting C++ Inheritance II, Casting CSE 333 Spring 2018 Instructor: Justin Hsia Teaching Assistants: Danny Allen Dennis Shao Eddie Huang Kevin Bi Jack Xu Matthew Neldam Michael Poulain Renshu Gu Robby Marver Waylon

More information

Polymorphism. Arizona State University 1

Polymorphism. Arizona State University 1 Polymorphism CSE100 Principles of Programming with C++, Fall 2018 (based off Chapter 15 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner. HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

Compaq Interview Questions And Answers

Compaq Interview Questions And Answers Part A: Q1. What are the difference between java and C++? Java adopts byte code whereas C++ does not C++ supports destructor whereas java does not support. Multiple inheritance possible in C++ but not

More information

CS3157: Advanced Programming. Outline

CS3157: Advanced Programming. Outline CS3157: Advanced Programming Lecture #12 Apr 3 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline Intro CPP Boring stuff: Language basics: identifiers, data types, operators, type conversions, branching

More information

COMP322 - Introduction to C++

COMP322 - Introduction to C++ COMP322 - Introduction to C++ Winter 2011 Lecture 08 - Inheritance continued School of Computer Science McGill University March 8, 2011 Last Time Single Inheritance Polymorphism: Static Binding vs Dynamic

More information

Introduction to C++ Systems Programming

Introduction to C++ Systems Programming Introduction to C++ Systems Programming Introduction to C++ Syntax differences between C and C++ A Simple C++ Example C++ Input/Output C++ Libraries C++ Header Files Another Simple C++ Example Inline Functions

More information

C++ Inheritance and Encapsulation

C++ Inheritance and Encapsulation C++ Inheritance and Encapsulation Private and Protected members Inheritance Type Public Inheritance Private Inheritance Protected Inheritance Special method inheritance 1 Private Members Private members

More information

C++ Programming: Inheritance

C++ Programming: Inheritance C++ Programming: Inheritance 2018 년도 2 학기 Instructor: Young-guk Ha Dept. of Computer Science & Engineering Contents Basics on inheritance C++ syntax for inheritance protected members Constructors and destructors

More information

Written by John Bell for CS 342, Spring 2018

Written by John Bell for CS 342, Spring 2018 Advanced OO Concepts Written by John Bell for CS 342, Spring 2018 Based on chapter 3 of The Object-Oriented Thought Process by Matt Weisfeld, with additional material from other sources. Constructors Constructors

More information

Exercise: Singleton 1

Exercise: Singleton 1 Exercise: Singleton 1 In some situations, you may create the only instance of the class. 1 class mysingleton { 2 3 // Will be ready as soon as the class is loaded. 4 private static mysingleton Instance

More information

Selected Java Topics

Selected Java Topics Selected Java Topics Introduction Basic Types, Objects and Pointers Modifiers Abstract Classes and Interfaces Exceptions and Runtime Exceptions Static Variables and Static Methods Type Safe Constants Swings

More information

Virtual functions concepts

Virtual functions concepts Virtual functions concepts l Virtual: exists in essence though not in fact l Idea is that a virtual function can be used before it is defined And it might be defined many, many ways! l Relates to OOP concept

More information

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U C A N A D I A N I N T E R N A T I O N A L S C H O O L O F H O N G K O N G INHERITANCE & POLYMORPHISM P2 LESSON 12 P2 LESSON 12.1 INTRODUCTION inheritance: OOP allows a programmer to define new classes

More information

Laboratorio di Tecnologie dell'informazione

Laboratorio di Tecnologie dell'informazione Laboratorio di Tecnologie dell'informazione Ing. Marco Bertini marco.bertini@unifi.it http://www.micc.unifi.it/bertini/ Const correctness What is const correctness? It is a semantic constraint, enforced

More information

Laboratorio di Tecnologie dell'informazione. Ing. Marco Bertini

Laboratorio di Tecnologie dell'informazione. Ing. Marco Bertini Laboratorio di Tecnologie dell'informazione Ing. Marco Bertini bertini@dsi.unifi.it http://www.dsi.unifi.it/~bertini/ Const correctness What is const correctness? It is a semantic constraint, enforced

More information

OBJ. ORI.& MULT. PROG., M.C.Q. BANK, FOR UNIT -2, SECOND YEAR COMP. ENGG. SEM-4, 2012 PATTERN, U.O.P. UNIT-2

OBJ. ORI.& MULT. PROG., M.C.Q. BANK, FOR UNIT -2, SECOND YEAR COMP. ENGG. SEM-4, 2012 PATTERN, U.O.P. UNIT-2 UNIT-2 Syllabus for Unit-2 Introduction, Need of operator overloading, overloading the assignment, binary and unary operators, overloading using friends, rules for operator overloading, type conversions

More information

Object-Oriented Programming, Iouliia Skliarova

Object-Oriented Programming, Iouliia Skliarova Object-Oriented Programming, Iouliia Skliarova CBook a = CBook("C++", 2014); CBook b = CBook("Physics", 1960); a.display(); b.display(); void CBook::Display() cout

More information