SlideShare a Scribd company logo
1 of 9
1 
8.11 Overloading ++ and -- 
 Increment/decrement operators can be 
overloaded 
 Add 1 to a Date object, d1 
 Prototype (member function) 
•Date &operator++(); 
•++d1 same as d1.operator++() 
 Prototype (non-member) 
•Friend Date &operator++( Date &); 
•++d1 same as operator++( d1 )
2 
8.11 Overloading ++ and -- 
 To distinguish pre/post increment 
 Post increment has a dummy parameter 
•int of 0 
 Prototype (member function) 
•Date operator++( int ); 
•d1++ same as d1.operator++( 0 ) 
 Prototype (non-member) 
•friend Date operator++( Data &, int 
); 
•d1++ same as operator++( d1, 0 ) 
 Integer parameter does not have a name 
 Not even in function definition
3 
8.11 Overloading ++ and -- 
 Return values 
 Preincrement 
 Returns by reference (Date &) 
 lvalue (can be assigned) 
 Postincrement 
 Returns by value 
 Returns temporary object with old value 
 rvalue (cannot be on left side of assignment) 
 Decrement operator analogous
4 
8.12 Case Study: A Date Class 
 Example Date class 
 Overloaded increment operator 
 Change day, month and year 
 Overloaded += operator 
 Function to test for leap years 
 Function to determine if day is last of month
5 
date1.h (1 of 2) 
1 // Fig. 8.10: date1.h 
2 // Date class definition. 
3 #ifndef DATE1_H 
4 #define DATE1_H 
5 #include <iostream> 
6 
Note difference between pre 
and post increment. 
7 using std::ostream; 
8 
9 class Date { 
10 friend ostream &operator<<( 
ostream &, const Date & ); 
11 
12 public: 
13 Date( int m = 1, int d = 1, int y = 
1900 ); // constructor
6 
date1.h (2 of 2) 
23 
24 private: 
25 int month; 
26 int day; 
27 int year; 
28 
29 static const int days[]; // 
array of days per month 
30 void helpIncrement(); // 
utility function 
31 
32 }; // end class Date 
33
date1.cpp (1 of 5) 
7 
1 // Fig. 8.11: date1.cpp 
2 // Date class member function 
definitions. 
3 #include <iostream> 
4 #include "date1.h" 
5 
6 // initialize static member at file 
scope; 
7 // one class-wide copy 
8 const int Date::days[] = 
9 { 0, 31, 28, 31, 30, 31, 30, 31, 
31, 30, 31, 30, 31 }; 
10 
11 // Date constructor 
12 Date::Date( int m, int d, int y )
date1.cpp (2 of 5) 
8 
24 // test for a leap year 
25 if ( month == 2 && leapYear( year ) ) 
26 day = ( dd >= 1 && dd <= 29 ) ? dd : 
1; 
27 else 
28 day = ( dd >= 1 && dd <= days[ 
month ] ) ? dd : 1; 
29 
30 } // end function setDate 
31 
Postincrement updates object 
and returns a copy of the 
original. Do not return a 
reference to temp, because it 
is a local variable that will be 
destroyed. 
32 // overloaded preincrement operator 
33 Date &Date::operator++() 
34 { 
35 helpIncrement(); 
36 
Also note that the integer 
parameter does not have a 
name. 
37 return *this; // reference return to 
create an lvalue 
38 
39 } // end function operator++
date1.cpp (3 of 5) 
9 
52 
53 // add specified number of days to 
date 
54 const Date &Date::operator+=( int 
additionalDays ) 
55 { 
56 for ( int i = 0; i < additionalDays; 
i++ ) 
57 helpIncrement(); 
58 
59 return *this; // enables 
cascading 
60 
61 } // end function operator+= 
62 
63 // if the year is a leap year, return

More Related Content

What's hot

No More Deadlocks; Asynchronous Programming in .NET
No More Deadlocks; Asynchronous Programming in .NETNo More Deadlocks; Asynchronous Programming in .NET
No More Deadlocks; Asynchronous Programming in .NETFilip Ekberg
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVMVaclav Pech
 
Richard Salter: Using the Titanium OpenGL Module
Richard Salter: Using the Titanium OpenGL ModuleRichard Salter: Using the Titanium OpenGL Module
Richard Salter: Using the Titanium OpenGL ModuleAxway Appcelerator
 
Ns2: OTCL - PArt II
Ns2: OTCL - PArt IINs2: OTCL - PArt II
Ns2: OTCL - PArt IIAjit Nayak
 
Ns2: Introduction - Part I
Ns2: Introduction - Part INs2: Introduction - Part I
Ns2: Introduction - Part IAjit Nayak
 
Vasia Kalavri – Training: Gelly School
Vasia Kalavri – Training: Gelly School Vasia Kalavri – Training: Gelly School
Vasia Kalavri – Training: Gelly School Flink Forward
 
NS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variablesNS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variablesTeerawat Issariyakul
 
The Singleton Pattern In Java
The Singleton Pattern In JavaThe Singleton Pattern In Java
The Singleton Pattern In JavaKohei Nozaki
 
Reacting with ReactiveUI
Reacting with ReactiveUIReacting with ReactiveUI
Reacting with ReactiveUIkiahiska
 
Process control nodejs
Process control nodejsProcess control nodejs
Process control nodejsLearningTech
 
RxJS - The Reactive extensions for JavaScript
RxJS - The Reactive extensions for JavaScriptRxJS - The Reactive extensions for JavaScript
RxJS - The Reactive extensions for JavaScriptViliam Elischer
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScriptMark Shelton
 
Java program-to-add-two-matrices
Java program-to-add-two-matricesJava program-to-add-two-matrices
Java program-to-add-two-matricesUniversity of Essex
 
NS2: AWK and GNUplot - PArt III
NS2: AWK and GNUplot - PArt IIINS2: AWK and GNUplot - PArt III
NS2: AWK and GNUplot - PArt IIIAjit Nayak
 
Ganga: an interface to the LHC computing grid
Ganga: an interface to the LHC computing gridGanga: an interface to the LHC computing grid
Ganga: an interface to the LHC computing gridMatt Williams
 
Vtk point cloud important
Vtk point cloud importantVtk point cloud important
Vtk point cloud importantRohit Bapat
 

What's hot (20)

201801 CSE240 Lecture 15
201801 CSE240 Lecture 15201801 CSE240 Lecture 15
201801 CSE240 Lecture 15
 
No More Deadlocks; Asynchronous Programming in .NET
No More Deadlocks; Asynchronous Programming in .NETNo More Deadlocks; Asynchronous Programming in .NET
No More Deadlocks; Asynchronous Programming in .NET
 
Rxjs ppt
Rxjs pptRxjs ppt
Rxjs ppt
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM
 
Angular2 rxjs
Angular2 rxjsAngular2 rxjs
Angular2 rxjs
 
Richard Salter: Using the Titanium OpenGL Module
Richard Salter: Using the Titanium OpenGL ModuleRichard Salter: Using the Titanium OpenGL Module
Richard Salter: Using the Titanium OpenGL Module
 
Ns2: OTCL - PArt II
Ns2: OTCL - PArt IINs2: OTCL - PArt II
Ns2: OTCL - PArt II
 
Ns2: Introduction - Part I
Ns2: Introduction - Part INs2: Introduction - Part I
Ns2: Introduction - Part I
 
Vasia Kalavri – Training: Gelly School
Vasia Kalavri – Training: Gelly School Vasia Kalavri – Training: Gelly School
Vasia Kalavri – Training: Gelly School
 
NS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variablesNS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variables
 
The Singleton Pattern In Java
The Singleton Pattern In JavaThe Singleton Pattern In Java
The Singleton Pattern In Java
 
Reacting with ReactiveUI
Reacting with ReactiveUIReacting with ReactiveUI
Reacting with ReactiveUI
 
Process control nodejs
Process control nodejsProcess control nodejs
Process control nodejs
 
RxJS - The Reactive extensions for JavaScript
RxJS - The Reactive extensions for JavaScriptRxJS - The Reactive extensions for JavaScript
RxJS - The Reactive extensions for JavaScript
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScript
 
Java program-to-add-two-matrices
Java program-to-add-two-matricesJava program-to-add-two-matrices
Java program-to-add-two-matrices
 
NS2: AWK and GNUplot - PArt III
NS2: AWK and GNUplot - PArt IIINS2: AWK and GNUplot - PArt III
NS2: AWK and GNUplot - PArt III
 
Ganga: an interface to the LHC computing grid
Ganga: an interface to the LHC computing gridGanga: an interface to the LHC computing grid
Ganga: an interface to the LHC computing grid
 
Intro
IntroIntro
Intro
 
Vtk point cloud important
Vtk point cloud importantVtk point cloud important
Vtk point cloud important
 

Viewers also liked

Maggio dei monumenti , associazioni in subbuglio.
Maggio dei monumenti , associazioni in subbuglio. Maggio dei monumenti , associazioni in subbuglio.
Maggio dei monumenti , associazioni in subbuglio. Daniela Petrecca
 
Social media en de Universiteit Utrecht
Social media en de Universiteit UtrechtSocial media en de Universiteit Utrecht
Social media en de Universiteit Utrechtmcuijland
 
La Guerra Civil Española Una aproximación al conflicto
La Guerra Civil Española Una aproximación al conflictoLa Guerra Civil Española Una aproximación al conflicto
La Guerra Civil Española Una aproximación al conflictoprofeshispanica
 
Réglement jeu nuits-sonores-2016
Réglement jeu nuits-sonores-2016Réglement jeu nuits-sonores-2016
Réglement jeu nuits-sonores-2016Coudray Laetitia
 
Employmentfirstwebinarpowerpointfinal09292016 160928150735(1)
Employmentfirstwebinarpowerpointfinal09292016 160928150735(1)Employmentfirstwebinarpowerpointfinal09292016 160928150735(1)
Employmentfirstwebinarpowerpointfinal09292016 160928150735(1)Michele Craig
 
News Awards, Courier Mail - Website of the Year
News Awards, Courier Mail - Website of the YearNews Awards, Courier Mail - Website of the Year
News Awards, Courier Mail - Website of the YearAndrew Webster
 
Para trabajar mejor vamos a ordenar la clase
Para trabajar mejor vamos a ordenar la clasePara trabajar mejor vamos a ordenar la clase
Para trabajar mejor vamos a ordenar la clasefedeul
 
Value Chain Management
Value Chain ManagementValue Chain Management
Value Chain ManagementAsintik
 

Viewers also liked (18)

Cities!
Cities!Cities!
Cities!
 
Maggio dei monumenti , associazioni in subbuglio.
Maggio dei monumenti , associazioni in subbuglio. Maggio dei monumenti , associazioni in subbuglio.
Maggio dei monumenti , associazioni in subbuglio.
 
Social media en de Universiteit Utrecht
Social media en de Universiteit UtrechtSocial media en de Universiteit Utrecht
Social media en de Universiteit Utrecht
 
Prueba de informatica
Prueba de informaticaPrueba de informatica
Prueba de informatica
 
Article about jose angel aguilar zavala
Article  about jose angel aguilar zavalaArticle  about jose angel aguilar zavala
Article about jose angel aguilar zavala
 
44444456
4444445644444456
44444456
 
La Guerra Civil Española Una aproximación al conflicto
La Guerra Civil Española Una aproximación al conflictoLa Guerra Civil Española Una aproximación al conflicto
La Guerra Civil Española Una aproximación al conflicto
 
Vulnerabilidad
VulnerabilidadVulnerabilidad
Vulnerabilidad
 
Réglement jeu nuits-sonores-2016
Réglement jeu nuits-sonores-2016Réglement jeu nuits-sonores-2016
Réglement jeu nuits-sonores-2016
 
I comuni al voto in piemonte
I comuni al voto in piemonteI comuni al voto in piemonte
I comuni al voto in piemonte
 
Employmentfirstwebinarpowerpointfinal09292016 160928150735(1)
Employmentfirstwebinarpowerpointfinal09292016 160928150735(1)Employmentfirstwebinarpowerpointfinal09292016 160928150735(1)
Employmentfirstwebinarpowerpointfinal09292016 160928150735(1)
 
News Awards, Courier Mail - Website of the Year
News Awards, Courier Mail - Website of the YearNews Awards, Courier Mail - Website of the Year
News Awards, Courier Mail - Website of the Year
 
Para trabajar mejor vamos a ordenar la clase
Para trabajar mejor vamos a ordenar la clasePara trabajar mejor vamos a ordenar la clase
Para trabajar mejor vamos a ordenar la clase
 
HYPEGIRL 2016*
HYPEGIRL 2016*HYPEGIRL 2016*
HYPEGIRL 2016*
 
Value Chain Management
Value Chain ManagementValue Chain Management
Value Chain Management
 
DOORDHARSHAN
DOORDHARSHANDOORDHARSHAN
DOORDHARSHAN
 
The Changing Payments Landscape
The Changing Payments LandscapeThe Changing Payments Landscape
The Changing Payments Landscape
 
Albania
AlbaniaAlbania
Albania
 

Similar to Synapse india dotnet development overloading operater part 4

Modify the Date class that was covered in the lecture which overload.pdf
Modify the Date class that was covered in the lecture which overload.pdfModify the Date class that was covered in the lecture which overload.pdf
Modify the Date class that was covered in the lecture which overload.pdfsaxenaavnish1
 
C++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdfC++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdfjaipur2
 
Please I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdfPlease I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdfankit11134
 
enum_comp_exercicio01.docx
enum_comp_exercicio01.docxenum_comp_exercicio01.docx
enum_comp_exercicio01.docxMichel Valentim
 
Seminar on conservative lif.ppt
Seminar on conservative lif.pptSeminar on conservative lif.ppt
Seminar on conservative lif.pptPujaRajput14
 
Chapter 1 Basic Concepts
Chapter 1 Basic ConceptsChapter 1 Basic Concepts
Chapter 1 Basic ConceptsHareem Aslam
 
Csphtp1 08
Csphtp1 08Csphtp1 08
Csphtp1 08HUST
 
Ch-4-Operator Overloading.pdf
Ch-4-Operator Overloading.pdfCh-4-Operator Overloading.pdf
Ch-4-Operator Overloading.pdfesuEthopi
 
Friend this-new&delete
Friend this-new&deleteFriend this-new&delete
Friend this-new&deleteShehzad Rizwan
 
friends functionToshu
friends functionToshufriends functionToshu
friends functionToshuSidd Singh
 

Similar to Synapse india dotnet development overloading operater part 4 (20)

Modify the Date class that was covered in the lecture which overload.pdf
Modify the Date class that was covered in the lecture which overload.pdfModify the Date class that was covered in the lecture which overload.pdf
Modify the Date class that was covered in the lecture which overload.pdf
 
C++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdfC++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdf
 
Please I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdfPlease I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdf
 
Operator overload rr
Operator overload  rrOperator overload  rr
Operator overload rr
 
enum_comp_exercicio01.docx
enum_comp_exercicio01.docxenum_comp_exercicio01.docx
enum_comp_exercicio01.docx
 
Seminar on conservative lif.ppt
Seminar on conservative lif.pptSeminar on conservative lif.ppt
Seminar on conservative lif.ppt
 
OOP.pptx
OOP.pptxOOP.pptx
OOP.pptx
 
C++ tutorials
C++ tutorialsC++ tutorials
C++ tutorials
 
Week7a.pptx
Week7a.pptxWeek7a.pptx
Week7a.pptx
 
Object Oriented Programming using C++ - Part 3
Object Oriented Programming using C++ - Part 3Object Oriented Programming using C++ - Part 3
Object Oriented Programming using C++ - Part 3
 
ThreeTen
ThreeTenThreeTen
ThreeTen
 
Jsr310
Jsr310Jsr310
Jsr310
 
Chapter 1 Basic Concepts
Chapter 1 Basic ConceptsChapter 1 Basic Concepts
Chapter 1 Basic Concepts
 
Csphtp1 08
Csphtp1 08Csphtp1 08
Csphtp1 08
 
Lecture5
Lecture5Lecture5
Lecture5
 
Overloading
OverloadingOverloading
Overloading
 
Ch-4-Operator Overloading.pdf
Ch-4-Operator Overloading.pdfCh-4-Operator Overloading.pdf
Ch-4-Operator Overloading.pdf
 
Python Programming Essentials - M23 - datetime module
Python Programming Essentials - M23 - datetime modulePython Programming Essentials - M23 - datetime module
Python Programming Essentials - M23 - datetime module
 
Friend this-new&delete
Friend this-new&deleteFriend this-new&delete
Friend this-new&delete
 
friends functionToshu
friends functionToshufriends functionToshu
friends functionToshu
 

More from Synapseindiappsdevelopment

Synapse india elance top in demand in it skills
Synapse india elance top in demand in it skillsSynapse india elance top in demand in it skills
Synapse india elance top in demand in it skillsSynapseindiappsdevelopment
 
SynapseIndia dotnet web development architecture module
SynapseIndia dotnet web development architecture moduleSynapseIndia dotnet web development architecture module
SynapseIndia dotnet web development architecture moduleSynapseindiappsdevelopment
 
SynapseIndia dotnet development platform overview
SynapseIndia  dotnet development platform overviewSynapseIndia  dotnet development platform overview
SynapseIndia dotnet development platform overviewSynapseindiappsdevelopment
 
SynapseIndia dotnet web applications development
SynapseIndia  dotnet web applications developmentSynapseIndia  dotnet web applications development
SynapseIndia dotnet web applications developmentSynapseindiappsdevelopment
 
SynapseIndia dotnet website security development
SynapseIndia  dotnet website security developmentSynapseIndia  dotnet website security development
SynapseIndia dotnet website security developmentSynapseindiappsdevelopment
 
SynapseIndia mobile apps deployment framework internal architecture
SynapseIndia mobile apps deployment framework internal architectureSynapseIndia mobile apps deployment framework internal architecture
SynapseIndia mobile apps deployment framework internal architectureSynapseindiappsdevelopment
 
SynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client librarySynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client librarySynapseindiappsdevelopment
 
SynapseIndia mobile apps deployment framework architecture
SynapseIndia mobile apps deployment framework architectureSynapseIndia mobile apps deployment framework architecture
SynapseIndia mobile apps deployment framework architectureSynapseindiappsdevelopment
 
SynapseIndia dotnet client library Development
SynapseIndia dotnet client library DevelopmentSynapseIndia dotnet client library Development
SynapseIndia dotnet client library DevelopmentSynapseindiappsdevelopment
 
SynapseIndia creating asp controls programatically development
SynapseIndia creating asp controls programatically developmentSynapseIndia creating asp controls programatically development
SynapseIndia creating asp controls programatically developmentSynapseindiappsdevelopment
 

More from Synapseindiappsdevelopment (20)

Synapse india elance top in demand in it skills
Synapse india elance top in demand in it skillsSynapse india elance top in demand in it skills
Synapse india elance top in demand in it skills
 
SynapseIndia dotnet web development architecture module
SynapseIndia dotnet web development architecture moduleSynapseIndia dotnet web development architecture module
SynapseIndia dotnet web development architecture module
 
SynapseIndia dotnet module development part 1
SynapseIndia  dotnet module development part 1SynapseIndia  dotnet module development part 1
SynapseIndia dotnet module development part 1
 
SynapseIndia dotnet framework library
SynapseIndia  dotnet framework librarySynapseIndia  dotnet framework library
SynapseIndia dotnet framework library
 
SynapseIndia dotnet development platform overview
SynapseIndia  dotnet development platform overviewSynapseIndia  dotnet development platform overview
SynapseIndia dotnet development platform overview
 
SynapseIndia dotnet development framework
SynapseIndia  dotnet development frameworkSynapseIndia  dotnet development framework
SynapseIndia dotnet development framework
 
SynapseIndia dotnet web applications development
SynapseIndia  dotnet web applications developmentSynapseIndia  dotnet web applications development
SynapseIndia dotnet web applications development
 
SynapseIndia dotnet website security development
SynapseIndia  dotnet website security developmentSynapseIndia  dotnet website security development
SynapseIndia dotnet website security development
 
SynapseIndia mobile build apps management
SynapseIndia mobile build apps managementSynapseIndia mobile build apps management
SynapseIndia mobile build apps management
 
SynapseIndia mobile apps deployment framework internal architecture
SynapseIndia mobile apps deployment framework internal architectureSynapseIndia mobile apps deployment framework internal architecture
SynapseIndia mobile apps deployment framework internal architecture
 
SynapseIndia java and .net development
SynapseIndia java and .net developmentSynapseIndia java and .net development
SynapseIndia java and .net development
 
SynapseIndia dotnet development panel control
SynapseIndia dotnet development panel controlSynapseIndia dotnet development panel control
SynapseIndia dotnet development panel control
 
SynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client librarySynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client library
 
SynapseIndia php web development
SynapseIndia php web developmentSynapseIndia php web development
SynapseIndia php web development
 
SynapseIndia mobile apps architecture
SynapseIndia mobile apps architectureSynapseIndia mobile apps architecture
SynapseIndia mobile apps architecture
 
SynapseIndia mobile apps deployment framework architecture
SynapseIndia mobile apps deployment framework architectureSynapseIndia mobile apps deployment framework architecture
SynapseIndia mobile apps deployment framework architecture
 
SynapseIndia mobile apps
SynapseIndia mobile appsSynapseIndia mobile apps
SynapseIndia mobile apps
 
SynapseIndia dotnet development
SynapseIndia dotnet developmentSynapseIndia dotnet development
SynapseIndia dotnet development
 
SynapseIndia dotnet client library Development
SynapseIndia dotnet client library DevelopmentSynapseIndia dotnet client library Development
SynapseIndia dotnet client library Development
 
SynapseIndia creating asp controls programatically development
SynapseIndia creating asp controls programatically developmentSynapseIndia creating asp controls programatically development
SynapseIndia creating asp controls programatically development
 

Recently uploaded

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

Synapse india dotnet development overloading operater part 4

  • 1. 1 8.11 Overloading ++ and --  Increment/decrement operators can be overloaded  Add 1 to a Date object, d1  Prototype (member function) •Date &operator++(); •++d1 same as d1.operator++()  Prototype (non-member) •Friend Date &operator++( Date &); •++d1 same as operator++( d1 )
  • 2. 2 8.11 Overloading ++ and --  To distinguish pre/post increment  Post increment has a dummy parameter •int of 0  Prototype (member function) •Date operator++( int ); •d1++ same as d1.operator++( 0 )  Prototype (non-member) •friend Date operator++( Data &, int ); •d1++ same as operator++( d1, 0 )  Integer parameter does not have a name  Not even in function definition
  • 3. 3 8.11 Overloading ++ and --  Return values  Preincrement  Returns by reference (Date &)  lvalue (can be assigned)  Postincrement  Returns by value  Returns temporary object with old value  rvalue (cannot be on left side of assignment)  Decrement operator analogous
  • 4. 4 8.12 Case Study: A Date Class  Example Date class  Overloaded increment operator  Change day, month and year  Overloaded += operator  Function to test for leap years  Function to determine if day is last of month
  • 5. 5 date1.h (1 of 2) 1 // Fig. 8.10: date1.h 2 // Date class definition. 3 #ifndef DATE1_H 4 #define DATE1_H 5 #include <iostream> 6 Note difference between pre and post increment. 7 using std::ostream; 8 9 class Date { 10 friend ostream &operator<<( ostream &, const Date & ); 11 12 public: 13 Date( int m = 1, int d = 1, int y = 1900 ); // constructor
  • 6. 6 date1.h (2 of 2) 23 24 private: 25 int month; 26 int day; 27 int year; 28 29 static const int days[]; // array of days per month 30 void helpIncrement(); // utility function 31 32 }; // end class Date 33
  • 7. date1.cpp (1 of 5) 7 1 // Fig. 8.11: date1.cpp 2 // Date class member function definitions. 3 #include <iostream> 4 #include "date1.h" 5 6 // initialize static member at file scope; 7 // one class-wide copy 8 const int Date::days[] = 9 { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 10 11 // Date constructor 12 Date::Date( int m, int d, int y )
  • 8. date1.cpp (2 of 5) 8 24 // test for a leap year 25 if ( month == 2 && leapYear( year ) ) 26 day = ( dd >= 1 && dd <= 29 ) ? dd : 1; 27 else 28 day = ( dd >= 1 && dd <= days[ month ] ) ? dd : 1; 29 30 } // end function setDate 31 Postincrement updates object and returns a copy of the original. Do not return a reference to temp, because it is a local variable that will be destroyed. 32 // overloaded preincrement operator 33 Date &Date::operator++() 34 { 35 helpIncrement(); 36 Also note that the integer parameter does not have a name. 37 return *this; // reference return to create an lvalue 38 39 } // end function operator++
  • 9. date1.cpp (3 of 5) 9 52 53 // add specified number of days to date 54 const Date &Date::operator+=( int additionalDays ) 55 { 56 for ( int i = 0; i < additionalDays; i++ ) 57 helpIncrement(); 58 59 return *this; // enables cascading 60 61 } // end function operator+= 62 63 // if the year is a leap year, return