SlideShare a Scribd company logo
Object-Oriented Programming
Review
1
Object-Oriented Programming
Object-Oriented Programming languages vary but
generally all support the following features:
Data Abstraction (encapsulation) – Define types
with an interface and hidden implementation.
Inheritance – Classes can inherit data or
behaviour.
Polymorphism – allows you create a hierarchy of
classes with a common interface.
2
C++ Revision
Classes have a public interface (methods only)
and a private implementation containing all data
members.
class Point {
public:
Point(int a, int b=0): x(a), y(b) {}
void draw() const;
private:
int x, y;
};
3
C++ Revision
Constructors are used to create and initialise a
new object. Every constructor should initalise
every data member.
A constructor with 1 parameter defines an
implicit conversion unless the constructor is
declared explicit.
Point p = 3; // Point p(3, 0);
p = 4; // p = Point(4)
4
C++ Revision
If you don’t write any constructors, the compile
will supply a default constructor.
Point(): x(), y() {}
The compiler also supplies default destructor,
copy constructor and assignment operator.
~Point() {}
Point(const Point& p): x(p.x), y(p.y) {}
Point& operator=(const Point& p) {
x = p.x; y = p.y; return *this;
}
5
C++ Revision
C++ classes can be referred to in three different
ways. Each have implications when assigning
variables to each other:
Point p(5, 10); // Actual instance
Point *p1 = &p; // p1 is a pointer to p
Point &p2 = p; // P2 is a reference to p
Point p3 = p; // Copy Constructor
p3 = p; // Assignment operator
Point *p4 = p1; // p1 and p3 both point to p
Point &p5 = p2; // (Same as Point p3 = p;)
6
C++ Revision
Methods which are defined in the class are
inline. Functions longer than a few lines should
not be defined here.
If the method has default arguments, they should
only be specified once.
What is the efficiency of passing instances,
references, pointers?
7
C++ Revision
Methods have access to private members of other
objects of the same class.
A function or class can be declared as a friend.
A friend has access to private data members.
8
C++ Static
Static data members are shared by all objects of a
class. It is initialised in a declaration outside the
class.
class Counter {
public:
Counter() {++count;}
~Counter() {--count;}
Counter(const Counter& c) {++count;}
Counter& operator=(const Counter& c) {return *this;}
static int getCount() {return count;}
private:
static int count;
};
int Counter::count = 0;
9
C++ Operators
Operators may be overloaded for classes as either
a global function with one parameter for each
operand or as a method of the left-hand operand.
Point operator+(const Point &a, const Point &b) {
return Point(a.getX()+b.getX(), a.getY()+b.getY());
}
Point Point::operator+(const Point &b) {
return Point(x+b.x, y+b.y);
}
10
C++ Inheritance
Inheritance allows a derived class to inherit all
the members of a base class except the
constructors, destructor and assignment
operator.
class Derived: public Base { ... };
class Duck: public Bird { ... };
class Square: public Rectangle { ... };
11
C++ Inheritance
Important terms you should know:
• pubic, private, protected base classes.
• Abstract and nonabstract base classes
• Virtual and nonvirtual member functions
12
C++ Polymorphism
Polymorphism class hierarchies consist of an
interface (abstract base class) and a set of derived
implementations.
Typically the base class has no data members or
code and derived classes do not add any new
public methods (except constructors).
13
C++ Overriding Methods
A method overriding a base method must have
the same parameters, return type and const-ness.
An overridden method must be virtual (in base
class) if the correct version is to be called through
a base pointer or reference.
14
C++ Programming
Generally you should not create objects of an
abstract class or interface.
The abstractness of a base class can be enforced
by either using protected constructors or pure
(=0) virtual methods.
A class with overridden methods should have a
public virtual destructor, even if it does nothing.
15
Example
class Complex{
public:
Complex(double real, double imaginary=0):
_real(real),_imaginary(imaginary){}
void operator+(Complex other){
_real = _real + other._real;
_imaginary = _imaginary + other._imaginary;
}
void operator <<(ostream os){
os <<"("<<_real<<","<<_imaginary<<")";
}
Complex operator++(){
++_real;
return *this;
}
Complex operator++(int){
Complex temp = *this;
++_real;
return temp;
}
private:
double _real,_imaginary;
};
16
Example
class Complex{
public:
explicit Complex(double real, double imaginary=0):
mReal(real),mImaginary(imaginary){}
Complex& operator+=(const Complex& other){
mReal += other.mReal;
mImaginary += other.mImaginary;
return *this;
}
Complex& operator++(){
++mReal;
return *this;
}
const Complex operator++(int){
Complex temp(*this);
++*this;
return temp;
}
private:
double mReal, mImaginary;
};
ostream& Print(ostream& os, Complex a) const {
return os << ...
}
17

More Related Content

Similar to polymorphism.ppt

C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1
ReKruiTIn.com
 
UNIT3 on object oriented programming.pptx
UNIT3 on object oriented programming.pptxUNIT3 on object oriented programming.pptx
UNIT3 on object oriented programming.pptx
urvashipundir04
 
Advanced programming topics asma
Advanced programming topics asmaAdvanced programming topics asma
Advanced programming topics asma
AbdullahJana
 
Unit 1 Part - 3 constructor Overloading Static.ppt
Unit 1 Part - 3  constructor Overloading Static.pptUnit 1 Part - 3  constructor Overloading Static.ppt
Unit 1 Part - 3 constructor Overloading Static.ppt
DeepVala5
 
Microsoft dynamics ax 2012 development introduction part 2/3
Microsoft dynamics ax 2012 development introduction part 2/3Microsoft dynamics ax 2012 development introduction part 2/3
Microsoft dynamics ax 2012 development introduction part 2/3
Ali Raza Zaidi
 
Classes cpp intro thomson bayan college
Classes cpp  intro thomson bayan collegeClasses cpp  intro thomson bayan college
Classes cpp intro thomson bayan college
ahmed hmed
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
Dr.Neeraj Kumar Pandey
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
rehan16091997
 
Oops concept in c#
Oops concept in c#Oops concept in c#
Oops concept in c#
ANURAG SINGH
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
1HK19CS090MOHAMMEDSA
 
14 operator overloading
14 operator overloading14 operator overloading
14 operator overloading
Docent Education
 
21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)
ssuser7f90ae
 
CJP Unit-1 contd.pptx
CJP Unit-1 contd.pptxCJP Unit-1 contd.pptx
CJP Unit-1 contd.pptx
RAJASEKHARV10
 
Major Java 8 features
Major Java 8 featuresMajor Java 8 features
Major Java 8 features
Sanjoy Kumar Roy
 
L6
L6L6
L6
lksoo
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)Jay Patel
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharma
Sandesh Sharma
 

Similar to polymorphism.ppt (20)

Inheritance
InheritanceInheritance
Inheritance
 
Csharp generics
Csharp genericsCsharp generics
Csharp generics
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1
 
UNIT3 on object oriented programming.pptx
UNIT3 on object oriented programming.pptxUNIT3 on object oriented programming.pptx
UNIT3 on object oriented programming.pptx
 
Advanced programming topics asma
Advanced programming topics asmaAdvanced programming topics asma
Advanced programming topics asma
 
Unit 1 Part - 3 constructor Overloading Static.ppt
Unit 1 Part - 3  constructor Overloading Static.pptUnit 1 Part - 3  constructor Overloading Static.ppt
Unit 1 Part - 3 constructor Overloading Static.ppt
 
Microsoft dynamics ax 2012 development introduction part 2/3
Microsoft dynamics ax 2012 development introduction part 2/3Microsoft dynamics ax 2012 development introduction part 2/3
Microsoft dynamics ax 2012 development introduction part 2/3
 
Classes cpp intro thomson bayan college
Classes cpp  intro thomson bayan collegeClasses cpp  intro thomson bayan college
Classes cpp intro thomson bayan college
 
Ds lab handouts
Ds lab handoutsDs lab handouts
Ds lab handouts
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
 
Oops concept in c#
Oops concept in c#Oops concept in c#
Oops concept in c#
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
14 operator overloading
14 operator overloading14 operator overloading
14 operator overloading
 
21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)
 
CJP Unit-1 contd.pptx
CJP Unit-1 contd.pptxCJP Unit-1 contd.pptx
CJP Unit-1 contd.pptx
 
Major Java 8 features
Major Java 8 featuresMajor Java 8 features
Major Java 8 features
 
L6
L6L6
L6
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharma
 

Recently uploaded

NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
ssuser7dcef0
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 

Recently uploaded (20)

NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 

polymorphism.ppt

  • 2. Object-Oriented Programming Object-Oriented Programming languages vary but generally all support the following features: Data Abstraction (encapsulation) – Define types with an interface and hidden implementation. Inheritance – Classes can inherit data or behaviour. Polymorphism – allows you create a hierarchy of classes with a common interface. 2
  • 3. C++ Revision Classes have a public interface (methods only) and a private implementation containing all data members. class Point { public: Point(int a, int b=0): x(a), y(b) {} void draw() const; private: int x, y; }; 3
  • 4. C++ Revision Constructors are used to create and initialise a new object. Every constructor should initalise every data member. A constructor with 1 parameter defines an implicit conversion unless the constructor is declared explicit. Point p = 3; // Point p(3, 0); p = 4; // p = Point(4) 4
  • 5. C++ Revision If you don’t write any constructors, the compile will supply a default constructor. Point(): x(), y() {} The compiler also supplies default destructor, copy constructor and assignment operator. ~Point() {} Point(const Point& p): x(p.x), y(p.y) {} Point& operator=(const Point& p) { x = p.x; y = p.y; return *this; } 5
  • 6. C++ Revision C++ classes can be referred to in three different ways. Each have implications when assigning variables to each other: Point p(5, 10); // Actual instance Point *p1 = &p; // p1 is a pointer to p Point &p2 = p; // P2 is a reference to p Point p3 = p; // Copy Constructor p3 = p; // Assignment operator Point *p4 = p1; // p1 and p3 both point to p Point &p5 = p2; // (Same as Point p3 = p;) 6
  • 7. C++ Revision Methods which are defined in the class are inline. Functions longer than a few lines should not be defined here. If the method has default arguments, they should only be specified once. What is the efficiency of passing instances, references, pointers? 7
  • 8. C++ Revision Methods have access to private members of other objects of the same class. A function or class can be declared as a friend. A friend has access to private data members. 8
  • 9. C++ Static Static data members are shared by all objects of a class. It is initialised in a declaration outside the class. class Counter { public: Counter() {++count;} ~Counter() {--count;} Counter(const Counter& c) {++count;} Counter& operator=(const Counter& c) {return *this;} static int getCount() {return count;} private: static int count; }; int Counter::count = 0; 9
  • 10. C++ Operators Operators may be overloaded for classes as either a global function with one parameter for each operand or as a method of the left-hand operand. Point operator+(const Point &a, const Point &b) { return Point(a.getX()+b.getX(), a.getY()+b.getY()); } Point Point::operator+(const Point &b) { return Point(x+b.x, y+b.y); } 10
  • 11. C++ Inheritance Inheritance allows a derived class to inherit all the members of a base class except the constructors, destructor and assignment operator. class Derived: public Base { ... }; class Duck: public Bird { ... }; class Square: public Rectangle { ... }; 11
  • 12. C++ Inheritance Important terms you should know: • pubic, private, protected base classes. • Abstract and nonabstract base classes • Virtual and nonvirtual member functions 12
  • 13. C++ Polymorphism Polymorphism class hierarchies consist of an interface (abstract base class) and a set of derived implementations. Typically the base class has no data members or code and derived classes do not add any new public methods (except constructors). 13
  • 14. C++ Overriding Methods A method overriding a base method must have the same parameters, return type and const-ness. An overridden method must be virtual (in base class) if the correct version is to be called through a base pointer or reference. 14
  • 15. C++ Programming Generally you should not create objects of an abstract class or interface. The abstractness of a base class can be enforced by either using protected constructors or pure (=0) virtual methods. A class with overridden methods should have a public virtual destructor, even if it does nothing. 15
  • 16. Example class Complex{ public: Complex(double real, double imaginary=0): _real(real),_imaginary(imaginary){} void operator+(Complex other){ _real = _real + other._real; _imaginary = _imaginary + other._imaginary; } void operator <<(ostream os){ os <<"("<<_real<<","<<_imaginary<<")"; } Complex operator++(){ ++_real; return *this; } Complex operator++(int){ Complex temp = *this; ++_real; return temp; } private: double _real,_imaginary; }; 16
  • 17. Example class Complex{ public: explicit Complex(double real, double imaginary=0): mReal(real),mImaginary(imaginary){} Complex& operator+=(const Complex& other){ mReal += other.mReal; mImaginary += other.mImaginary; return *this; } Complex& operator++(){ ++mReal; return *this; } const Complex operator++(int){ Complex temp(*this); ++*this; return temp; } private: double mReal, mImaginary; }; ostream& Print(ostream& os, Complex a) const { return os << ... } 17