A <Basic> C++ Course
|
|
- Clarissa James
- 6 years ago
- Views:
Transcription
1 adapted from Jean-Paul Rigault courses 1 A <Basic> C++ Course 8 Object-oriented programming 2 Julien Deantoni
2 2 Outline Dynamic Typing Truncature Cast
3 3 Variants of class Paragraph Definition of derived classes (1) We wish to have several sorts of paragraphs titles, sections, enumerations, items... We want to share as much as possible the common properties contents as a string possibility to (crude lay out) But specific properties should be possible numbering, bullets... page layout
4 4 Variants of class Paragraph Definition of derived classes (5) A derived class may add new properties data members member-functions friend functions A derived class may redefine (override) some inherited memberfunctions Derivation depth is unlimited Single and multiple inheritance Single: only one base class Multiple: several distinct base classes
5 If (int, int) is NON virtual 5
6 Paragraph::Paragraph(std::string title std::string content) { _title = title; _content = content; } If (int, int) is NON virtual 6
7 content depth Paragraph::Paragraph(std::string title std::string content) { _title = title; _content = content; } If (int, int) is NON virtual 7
8 Paragraph::Paragraph(std::string title std::string content) { _title = title; _content = content; } If (int, int) is NON virtual 8
9 Item_Paragraph::Item_Paragraph(string title, string content, char b) :Paragraph(title,content) { _bullet = b; } If (int, int) is NON virtual and is not redefined in Item_Paragraph 9
10 ip:item_paragraph content depth Item_Paragraph::Item_Paragraph(string title, string content, char b) :Paragraph(title,content) { _bullet = b; } If (int, int) is NON virtual and is not redefined in Item_Paragraph 10
11 ip:item_paragraph content depth Bullet Item_Paragraph::Item_Paragraph(string title, string content, char b) :Paragraph(title,content) { _bullet = b; } If (int, int) is NON virtual and is not redefined in Item_Paragraph 11
12 ip:item_paragraph Bullet Item_Paragraph::Item_Paragraph(string title, string content, string b) :Paragraph(title,content) { _bullet = b; } If (int, int) is NON virtual and is not redefined in Item_Paragraph 12
13 ip:item_paragraph Bullet='#' Item_Paragraph::Item_Paragraph(string title, string content, string b) :Paragraph(title,content) { _bullet = b; } If (int, int) is NON virtual and is not redefined in Item_Paragraph 13
14 ip:item_paragraph Bullet='#' If (int, int) is NON virtual and is REDEFINED in Item_Paragraph 14
15 ip:item_paragraph Bullet='#' p.(); ip.(); If (int, int) is NON virtual and is REDEFINED in Item_Paragraph 15
16 ip:item_paragraph Bullet='#' p.(); ip.(); What if we create a vector of Paragraphs?? If (int, int) is NON virtual and is REDEFINED in Item_Paragraph 16
17 vp:vector ip:item_paragraph Bullet='#' vector<paragraph> vp; If (int, int) is NON virtual and is REDEFINED in Item_Paragraph 17
18 vp:vector pbis:paragraph ip:item_paragraph Bullet='#' vector<paragraph> vp; vp.push_back(p); If (int, int) is NON virtual and is REDEFINED in Item_Paragraph 18
19 vp:vector pbis:paragraph iptrunc:paragraph ip:item_paragraph Bullet='#' vector<paragraph> vp; vp.push_back(p); vp.push_back(ip); If (int, int) is NON virtual and is REDEFINED in Item_Paragraph 19
20 vp:vector pbis:paragraph iptrunc:paragraph ip:item_paragraph Bullet='#' vector<paragraph> vp; vp.push_back(p); vp.push_back(ip); We lost the specificities of Item_Paragraph If (int, int) is NON virtual and is REDEFINED in Item_Paragraph 20
21 vp:vector pbis:paragraph iptrunc:paragraph ip:item_paragraph Bullet='#' vector<paragraph> vp; vp.push_back(p); vp.push_back(ip); We lost the specificities of Item_Paragraph... Forever! If (int, int) is NON virtual and is REDEFINED in Item_Paragraph 21
22 vptr_p:vector ip: Item_Paragraph Bullet='#' vector<paragraph*> vptr_p What happens if we create a vector of paragraph pointer? If (int, int) is NON VIRTUAL and is redefined in Item_Paragraph 22
23 vptr_p:vector :paragraph* :paragraph* ip: Item_Paragraph Bullet='#' vector<paragraph*> vptr_p vptr_p.push_back(&p); vptr_p.push_back(&ip); If (int, int) is NON VIRTUAL and is redefined in Item_Paragraph 23
24 vptr_p:vector :paragraph* :paragraph* ip: Item_Paragraph Typed by Paragraph content depth Bullet='#' vector<paragraph*> vptr_p vptr_p.push_back(&p); vptr_p.push_back(&ip); A call to a non-virtual function is resolved according to the static type of the hidden parameter If (int, int) is NON VIRTUAL and is redefined in Item_Paragraph 24
25 Paragraph vtable p.(); If (int, int) is VIRTUAL and is REDEFINED in Item_Paragraph 25
26 Paragraph vtable ip:item_paragraph Bullet='#' Item_Paragraph vtable p.(); ip.(); If (int, int) is VIRTUAL and is REDEFINED in Item_Paragraph 26
27 Paragraph vtable ip:item_paragraph Bullet='#' Item_Paragraph vtable p.(); ip.(); What happens if we create a vector of Paragraphs?? If (int, int) is VIRTUAL and is REDEFINED in Item_Paragraph 27
28 vp:vector pbis: Paragraph Paragraph vtable iptrunc:paragraph ip:item_paragraph Bullet='#' Item_Paragraph vtable vector<paragraph> vp; vp.push_back(p); vp.push_back(ip); We lost the specificities of Item_Paragraph If (int, int) is VIRTUAL and is REDEFINED in Item_Paragraph 28
29 vptr_p:vector Paragraph vtable ip:item_paragraph Bullet='#' Item_Paragraph vtable vector<paragraph*> vptr_p What happens if we create a vector of paragraph pointer? If (int, int) is VIRTUAL and is REDEFINED in Item_Paragraph 29
30 vptr_p:vector :paragraph* Paragraph vtable ip:item_paragraph Bullet='#' Item_Paragraph vtable vector<paragraph*> vptr_p vptr_p.push_back(&p); If (int, int) is VIRTUAL and is REDEFINED in Item_Paragraph 30
31 vptr_p:vector :paragraph* :paragraph* Paragraph vtable ip:item_paragraph Bullet='#' A call to a virtual function is resolved according to the type dynamic type of the hidden parameter Item_Paragraph vtable vector<paragraph*> vptr_p vptr_p.push_back(&p); vptr_p.push_back(&ip); If (int, int) is VIRTUAL and is REDEFINED in Item_Paragraph 31
32 vptr_p:vector :paragraph* :paragraph* :paragraph* ip:item_paragraph Bullet='#' :Paragraph Paragraph vtable Item_Paragraph vtable vector<paragraph*> vptr_p vptr_p.push_back(&p); vptr_p.push_back(&ip); vptr_p.push_back(new Paragraph(ip)); If (int, int) is VIRTUAL and is REDEFINED in Item_Paragraph 32
33 vptr_p:vector :paragraph* :paragraph* :paragraph* ip:item_paragraph Bullet='#' :Paragraph Paragraph vtable Item_Paragraph vtable vector<paragraph*> vptr_p vptr_p.push_back(&p); vptr_p.push_back(&ip); vptr_p.push_back(new Paragraph(ip)); You have to use the clone() virtual function (course 8-OO.pdf) If (int, int) is VIRTUAL and is REDEFINED in Item_Paragraph 33
34 34 Abstract classes and pure virtual functions Object is abstract It cannot be instantiated Some of its behaviors cannot be defined at least one of its member function is a pure virtual function
35 35 Abstract classes and pure virtual functions Object is abstract It cannot be instantiated Some of its behaviors cannot be defined at least one of its member function is a pure virtual function pure virtual functions
36 36 Safe downward cast (1) Downward cast may be dangerous class A {... }; class B : public A { void f() {... } }; // f() not defined in A
37 37 Safe downward cast (1) Downward cast may be dangerous class A {... }; class B : public A { void f() {... } }; // f() not defined in A A* pa = new B(); // OK pa:a* :B f()
38 38 Safe downward cast (1) Downward cast may be dangerous class A {... }; class B : public A { void f() {... } }; // f() not defined in A A* pa = new B(); // OK pa >f(); pa:a* :B f()
39 39 Safe downward cast (1) Downward cast may be dangerous class A {... }; class B : public A { void f() {... } }; // f() not defined in A A* pa = new B(); // OK pa >f(); // KO Typed by pa:a* A :B f()
40 40 Safe downward cast (1) Downward cast may be dangerous class A {... }; class B : public A { void f() {... } }; // f() not defined in A A* pa = new B(); // OK pa >f(); // KO ((B*)pa) >f(); // OK casted and then typed by (B*)pa:B* pa:a* B f() :B f()
41 41 Safe downward cast (1) Downward cast may be dangerous class A {... }; class B : public A { void f() {... } }; // f() not defined in A A* pa = new A(); // OK pa >f(); // KO ((B*)pa) >f(); // OK casted and then typed by (B*)pa:B* pa:a* :B f() :B :A f() Unsafe!!
42 42 Safe downward cast (1) Downward cast may be dangerous class A {... }; class B : public A { void f() {... } }; // f() not defined in A B* pa = new A(); // KO pa:b* pa:a* :B :A f()
43 43 Safe downward cast (1) Downward cast may be dangerous class A {... }; class B : public A { void f() {... } }; // f() not defined in A A* pa = new B(); // OK pa >f(); // KO ((B*)pa) >f(); // OK casted and then typed by pa:a* :B :B f() static_cast<b*>(pa) >f();// OK Unsafe!!
44 44 Safe downward cast (2) Operator dynamic_cast B *pb = dynamic_cast<b*>(pa); if (pb!= nullptr) { pb >f(); // OK and safe }
45 45 Safe downward cast (2) Operator dynamic_cast B *pb = dynamic_cast<b*>(pa); if (pb!= nullptr) pb >f(); // OK and safe try { dynamic_cast<b*>(pa) >f(); } catch(bad_cast) { cerr << "bad conversion" << endl; }
46 46 Safe downward cast (3) Limitation of dynamic_cast Work only on classes with virtual functions (polymorphic types) Invoking dynamic_cast from a constructor or a destructor dynamic_cast behaves like a virtual function it is statically bound in a constructor or a destructor
A <Basic> C++ Course
adapted from Jean-Paul Rigault courses 1 A C++ Course 7 Object-oriented programming Julien DeAntoni Outline Introduction to class derivation: variants of class Paragraph Dynamic typing and virtual
More informationA <Basic> C++ Course
A C++ Course 7 Object-oriented programming Julien Deantoni adapted from Jean-Paul Rigault courses Outline Introduction to class derivation: variants of class Paragraph Dynamic typing and virtual
More informationPOLYMORPHISM 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 informationPOLYMORPHISM 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 informationPolymorphism. 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 informationCOMP322 - 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 informationC++ 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 informationC++ Programming: Polymorphism
C++ Programming: Polymorphism 2018 년도 2 학기 Instructor: Young-guk Ha Dept. of Computer Science & Engineering Contents Run-time binding in C++ Abstract base classes Run-time type identification 2 Function
More information04-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 informationC++ 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 informationIncreases 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 informationInheritance, 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 informationInheritance and Polymorphism
Division of Mathematics and Computer Science Maryville College Outline Inheritance 1 Inheritance 2 3 Outline Inheritance 1 Inheritance 2 3 The "is-a" Relationship The "is-a" Relationship Object classification
More information15: 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 informationInheritance and Polymorphism
Division of Mathematics and Computer Science Maryville College Outline Inheritance 1 Inheritance 2 3 Outline Inheritance 1 Inheritance 2 3 The "is-a" Relationship Object classification is typically hierarchical.
More informationVIRTUAL 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 informationQUIZ. 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 informationCS105 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 informationWhat 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 informationPolymorphism 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 informationCOMP322 - 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 informationG 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 informationC++ Important Questions with Answers
1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children
More informationObject Oriented Programming with c++ Question Bank
Object Oriented Programming with c++ Question Bank UNIT-1: Introduction to C++ 1. Describe the following characteristics of OOP. i Encapsulation ii Polymorphism, iii Inheritance 2. Discuss function prototyping,
More informationXII- COMPUTER SCIENCE VOL-II MODEL TEST I
MODEL TEST I 1. What is the significance of an object? 2. What are Keyword in c++? List a few Keyword in c++?. 3. What is a Pointer? (or) What is a Pointer Variable? 4. What is an assignment operator?
More informationIntroduction 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 informationOBJECT 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 informationProgramming 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 informationAbsolute 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 informationProgramming Languages: OO Paradigm, Polymorhism and Class Members
Programming Languages: OO Paradigm, Polymorhism and Class Members Onur Tolga Şehitoğlu Computer Engineering,METU 1 May 2009 Outline 1 2 Abstract Classes Inheritance inclusion polymorphism Binding is still
More informationLogistics. Templates. Plan for today. Logistics. A quick intro to Templates. A quick intro to Templates. Project. Questions? Introduction to Templates
Logistics Templates Project Part 1 (clock and design) due Sunday, Sept 25 th Start thinking about partners for Parts 2-3 Questions? Logistics Important date: THURSDAY is Exam 1 Will cover: C++ environment
More informationKLiC C++ Programming. (KLiC Certificate in C++ Programming)
KLiC C++ Programming (KLiC Certificate in C++ Programming) Turbo C Skills: Pre-requisite Knowledge and Skills, Inspire with C Programming, Checklist for Installation, The Programming Languages, The main
More informationIntro 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 informationA <Basic> C++ Course
A C++ Course 5 Constructors / destructors operator overloading Julien DeAntoni adapted from Jean-Paul Rigault courses 1 2 This Week A little reminder Constructor / destructor Operator overloading
More informationSubtyping (Dynamic Polymorphism)
Fall 2018 Subtyping (Dynamic Polymorphism) Yu Zhang Course web site: http://staff.ustc.edu.cn/~yuzhang/tpl References PFPL - Chapter 24 Structural Subtyping - Chapter 27 Inheritance TAPL (pdf) - Chapter
More informationG52CPP C++ Programming Lecture 14. Dr Jason Atkin
G52CPP C++ Programming Lecture 14 Dr Jason Atkin 1 Last Lecture Automatically created methods: A default constructor so that objects can be created without defining a constructor A copy constructor used
More informationCHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object
CHAPTER 1 Introduction to Computers and Programming 1 1.1 Why Program? 1 1.2 Computer Systems: Hardware and Software 2 1.3 Programs and Programming Languages 8 1.4 What is a Program Made of? 14 1.5 Input,
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 Key Concepts Polymorphism virtual functions Virtual function tables
More informationPointers and References
Steven Zeil October 2, 2013 Contents 1 References 2 2 Pointers 8 21 Working with Pointers 8 211 Memory and C++ Programs 11 212 Allocating Data 15 22 Pointers Can Be Dangerous 17 3 The Secret World of Pointers
More informationWeek 7. Statically-typed OO languages: C++ Closer look at subtyping
C++ & Subtyping Week 7 Statically-typed OO languages: C++ Closer look at subtyping Why talk about C++? C++ is an OO extension of C Efficiency and flexibility from C OO program organization from Simula
More informationPolymorphism. 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 informationObject 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 informationOOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.
OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.
More informationOverview. Constructors and destructors Virtual functions Single inheritance Multiple inheritance RTTI Templates Exceptions Operator Overloading
How C++ Works 1 Overview Constructors and destructors Virtual functions Single inheritance Multiple inheritance RTTI Templates Exceptions Operator Overloading Motivation There are lot of myths about C++
More informationC++ 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 informationOverview. Constructors and destructors Virtual functions Single inheritance Multiple inheritance RTTI Templates Exceptions Operator Overloading
HOW C++ WORKS Overview Constructors and destructors Virtual functions Single inheritance Multiple inheritance RTTI Templates Exceptions Operator Overloading Motivation There are lot of myths about C++
More informationG52CPP C++ Programming Lecture 13
G52CPP C++ Programming Lecture 13 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last lecture Function pointers Arrays of function pointers Virtual and non-virtual functions vtable and
More informationMidterm Exam 5 April 20, 2015
Midterm Exam 5 April 20, 2015 Name: Section 1: Multiple Choice Questions (24 pts total, 3 pts each) Q1: Which of the following is not a kind of inheritance in C++? a. public. b. private. c. static. d.
More informationPolymorphism. 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 informationCpt 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 informationWhere 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 informationC++ (classes) Hwansoo Han
C++ (classes) Hwansoo Han Inheritance Relation among classes shape, rectangle, triangle, circle, shape rectangle triangle circle 2 Base Class: shape Members of a class Methods : rotate(), move(), Shape(),
More informationObject-Oriented Programming
iuliana@cs.ubbcluj.ro Babes-Bolyai University 2018 1 / 40 Overview 1 2 3 4 5 2 / 40 Primary OOP features ion: separating an object s specification from its implementation. Encapsulation: grouping related
More informationObject 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 informationCOEN244: Polymorphism
COEN244: Polymorphism Aishy Amer Electrical & Computer Engineering Polymorphism means variable behavior / ability to appear in many forms Outline Casting between objects Using pointers to access objects
More informationObject 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 information1. An object of a class can be treated as an object of its corresponding class.
Instructions: This homework assignment covers the basics of inheritance and polymorphism in C++. The answers may be determined from the lecture notes and assigned reading in Weiss. 1. An object of a class
More informationA <Basic> C++ Course. Julien DeAntoni. 7 - The document example. adapted from Jean-Paul Rigault courses
adapted from Jean-Paul Rigault courses 1 A C++ Course 7 - The document example Julien DeAntoni 2 This Week Just an example... 3 Document example: basic specifications Consider (unstructured) text
More informationG52CPP C++ Programming Lecture 12
G52CPP C++ Programming Lecture 12 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last lecture this and static members References Act like pointers Look like values More const And mutable
More informationA <Basic> C++ Course. Julien Deantoni. 7 - The document example. adapted from Jean-Paul Rigault courses
A C++ Course 7 - The document example Julien Deantoni adapted from Jean-Paul Rigault courses This Week Just an example... Programmation multi paradigmes en C++ 2 Document example: basic specifications
More informationCOMP6771 Advanced C++ Programming
1 COMP6771 Advanced C++ Programming Week 11 Object Oriented Programming 2016 www.cse.unsw.edu.au/ cs6771 2 Covariants and Contravariants Let us assume that Class B is a subtype of class A. Covariants:
More informationCMSC 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 informationCS 162, Lecture 25: Exam II Review. 30 May 2018
CS 162, Lecture 25: Exam II Review 30 May 2018 True or False Pointers to a base class may be assigned the address of a derived class object. In C++ polymorphism is very difficult to achieve unless you
More informationPassing arguments to functions by. const member functions const arguments to a function. Function overloading and overriding Templates
Lecture-4 Inheritance review. Polymorphism Virtual functions Abstract classes Passing arguments to functions by Value, pointers, refrence const member functions const arguments to a function Function overloading
More informationG Programming Languages Spring 2010 Lecture 9. Robert Grimm, New York University
G22.2110-001 Programming Languages Spring 2010 Lecture 9 Robert Grimm, New York University 1 Review Last week Modules 2 Outline Classes Encapsulation and Inheritance Initialization and Finalization Dynamic
More informationOBJECT 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 informationExtending 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 informationA <Basic> C++ Course
A C++ Course 5 Constructors / destructors operator overloading Julien Deantoni adapted from Jean-Paul Rigault courses This Week A little reminder Constructor / destructor Operator overloading Programmation
More informationXII CS(EM) Minimum Question List N.KANNAN M.Sc., B.Ed COMPUTER SCIENCE IMPORTANT QUESTION (TWO MARKS) CHAPTER 1 TO 5 ( STAR OFFICE WRITER)
COMPUTER SCIENCE IMPORTANT QUESTION (TWO MARKS) CHAPTER 1 TO 5 ( STAR OFFICE WRITER) 1. Selecting text with keyboard 2. Differ copying and moving 3. Text Editing 4. Creating a bulleted list 5. Creating
More informationC++ Yanyan SHEN. slide 1
C++ Yanyan SHEN slide 1 History C++ is an object-oriented extension of C Designed by Bjarne Stroustrup at Bell Labs His original interest at Bell Labs was research on simulation Early extensions to C are
More informationWelcome to Teach Yourself Acknowledgments Fundamental C++ Programming p. 2 An Introduction to C++ p. 4 A Brief History of C++ p.
Welcome to Teach Yourself p. viii Acknowledgments p. xv Fundamental C++ Programming p. 2 An Introduction to C++ p. 4 A Brief History of C++ p. 6 Standard C++: A Programming Language and a Library p. 8
More informationChapter 15. Object-Oriented Programming
number of operands as their built-in counterparts. user-defined conversion A synonym for class-type conversion. Chapter 15. Object-Oriented Programming Contents Section 15.1 OOP: An Overview Section 15.2
More informationOOP 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엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2015 EOM, HYEONSANG ALL RIGHTS RESERVED
엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2015 EOM, HYEONSANG ALL RIGHTS RESERVED Outline - Object Oriented Programming (OOP) - Basic Terms -
More informationIS 0020 Program Design and Software Tools
1 IS 0020 Program Design and Software Tools Introduction to C++ Programming Multiple Inheritance July 26, 2004 22.9 Multiple Inheritance 2 Multiple inheritance Derived class has several base classes Powerful,
More informationObject-Oriented Programming, Iouliia Skliarova
Object-Oriented Programming, Iouliia Skliarova You reuse code by creating new classes, but instead of creating them from scratch, you use existing classes that someone else has built and debugged. In composition
More informationIntroduction to Move Semantics in C++ C and C
Introduction to Move Semantics in C++ C++ 2011 and C++ 2014 Jean-Paul RIGAULT University of Nice - Sophia Antipolis Engineering School Computer Science Department Sophia Antipolis, France Contents of the
More informationWhat 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 informationShort 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 informationCSE 333 Lecture 15 - inheritance
CSE 333 Lecture 15 - inheritance Hal Perkins Department of Computer Science & Engineering University of Washington Administrivia HW3 due a week from Thursday - how s it look? - Section tomorrow: HW3 debugging
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 - Polymorphism - Virtual Functions - Abstract Classes - Virtual
More informationSyllabus of C++ Software for Hands-on Learning: This course offers the following modules: Module 1: Getting Started with C++ Programming
Syllabus of C++ Software for Hands-on Learning: Borland C++ 4.5 Turbo C ++ V 3.0 This course offers the following modules: Module 1: Getting Started with C++ Programming Audience for this Course Job Roles
More informationAdvanced C++ Topics. Alexander Warg, 2017
www.kernkonzept.com Advanced C++ Topics Alexander Warg, 2017 M I C R O K E R N E L M A D E I N G E R M A N Y Overview WHAT IS BEHIND C++ Language Magics Object Life Time Object Memory Layout INTRODUCTION
More informationData 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 informationOverriding Variables: Shadowing
Overriding Variables: Shadowing We can override methods, can we override instance variables too? Answer: Yes, it is possible, but not recommended Overriding an instance variable is called shadowing, because
More informationLaboratorio di Tecnologie dell'informazione
Laboratorio di Tecnologie dell'informazione Ing. Marco Bertini marco.bertini@unifi.it http://www.micc.unifi.it/bertini/ Inheritance "In the one and only true way, the object-oriented version of Spaghetti
More informationCS201 - 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 informationCS250 Intro to CS II. Spring CS250 - Intro to CS II 1
CS250 Intro to CS II Spring 2017 CS250 - Intro to CS II 1 Topics Virtual Functions Pure Virtual Functions Abstract Classes Concrete Classes Binding Time, Static Binding, Dynamic Binding Overriding vs Redefining
More informationObject-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 informationECE 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 informationTemplate Issue Resolutions from the Stockholm Meeting
96-0153/N0971 Template Issue Resolutions from the Stockholm Meeting 1 X3J16/96-0153 WG21/N0971 July 9 th, 1996 John H. Spicer, Edison Design Group Template Issue Resolutions from the Stockholm Meeting
More informationInstantiation 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 informationCS11 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 informationReview and Recursion
Midterm Exam Review Division of Mathematics and Computer Science Maryville College Outline Midterm Exam Review 1 Midterm Exam Review 2 Questions 1-10 Midterm Exam Review 1 What are some of the main challenges
More informationECE 2400 Computer Systems Programming Fall 2017 Topic 14: C++ Inheritance
ECE 200 Computer Systems Programming Fall 2017 Topic 1: C++ Inheritance School of Electrical and Computer Engineering Cornell University revision: 2017-11-06-09-36 1 Introduction to C++ Inheritance 2 1.1.
More informationChapter 5. Object- Oriented Programming Part I
Chapter 5 Object- Oriented Programming Part I 5: Preview basic terminology comparison of the Java and C++ approaches to polymorphic programming techniques introduced before in the context of inheritance:
More informationPolymorphism. 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 informationEMBEDDED SYSTEMS PROGRAMMING OO Basics
EMBEDDED SYSTEMS PROGRAMMING 2014-15 OO Basics CLASS, METHOD, OBJECT... Class: abstract description of a concept Object: concrete realization of a concept. An object is an instance of a class Members Method:
More informationIntroduction 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 informationDynamic 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