A <Basic> C++ Course

Similar documents
A <Basic> C++ Course

CSI33 Data Structures

Abstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles

CS 247: Software Engineering Principles. ADT Design

Reference Parameters A reference parameter is an alias for its corresponding argument in the function call. Use the ampersand (&) to indicate that

Copy Constructor, Assignment, Equality

Structuur van Computerprogramma s 2

KOM3191 Object Oriented Programming Dr Muharrem Mercimek OPERATOR OVERLOADING. KOM3191 Object-Oriented Programming

Overloading Operators in C++

Review. What is const member data? By what mechanism is const enforced? How do we initialize it? How do we initialize it?

Distributed Real-Time Control Systems. Lecture 17 C++ Programming Intro to C++ Objects and Classes

Circle all of the following which would make sense as the function prototype.

More Advanced Class Concepts

EINDHOVEN UNIVERSITY OF TECHNOLOGY Department of Mathematics and Computer Science

Object-Oriented Programming

Review: C++ Basic Concepts. Dr. Yingwu Zhu

Module Operator Overloading and Type Conversion. Table of Contents

Ch. 12: Operator Overloading

Vectors of Pointers to Objects. Vectors of Objects. Vectors of unique ptrs C++11. Arrays of Objects

ADTs & Classes. An introduction

Note 11/13/2014. They are like those i s, j s, and temp s that appear and disappear when the function starts and finishes...

CS 215 Fundamentals of Programming II Spring 2011 Project 2

G52CPP C++ Programming Lecture 13

Abstract Data Types. Development and Implementation. Well-defined representations that allow objects to be created and used in an intuitive manner

2 ADT Programming User-defined abstract data types

This chapter introduces the notion of namespace. We also describe how to manage input and output with C++ commands via the terminal or files.

14.1. Chapter 14: static member variable. Instance and Static Members 8/23/2014. Instance and Static Members

CS11 Intro C++ Spring 2018 Lecture 5

CISC 2200 Data Structure Fall, C++ Review:3/3. 1 From last lecture:

Ch 8. Operator Overloading, Friends, and References

CPSC 427: Object-Oriented Programming

IS0020 Program Design and Software Tools Midterm, Fall, 2004

Due Date: See Blackboard

Programmation avancée pour le calcul scientifique Lecture title: Classes

Chapter 18 - C++ Operator Overloading

AN OVERVIEW OF C++ 1

Short Notes of CS201

CSC 330 Object Oriented Programming. Operator Overloading Friend Functions & Forms

Evolution of Programming Languages

17. Classes. Overloading Functions. Operator Overloading. Function Overloading. operatorop

C++ 8. Constructors and Destructors

Software Engineering Concepts: Invariants Silently Written & Called Functions Simple Class Example

CS201 - Introduction to Programming Glossary By

CSS 342 Data Structures, Algorithms, and Discrete Mathematics I. Lecture 2. Yusuf Pisan

Overloaded Operators, Functions, and Students

Use the dot operator to access a member of a specific object.

Introduction Of Classes ( OOPS )

CS304 Object Oriented Programming Final Term

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi

Where do we go from here?

G52CPP C++ Programming Lecture 17

(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University

Convenient way to deal large quantities of data. Store data permanently (until file is deleted).

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

SFU CMPT Topic: Class Templates

Operator Overloading in C++ Systems Programming

G52CPP C++ Programming Lecture 14. Dr Jason Atkin

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts

Interview Questions of C++

Intermediate Programming, Spring 2017*

Object-Oriented Principles and Practice / C++

III. Classes (Chap. 3)

cs3157: c++ lecture #2 (mon-11-apr-2005) chronology of some programming languages... C++ vs Java identifiers.

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

pointers & references

Program construction in C++ for Scientific Computing

SFU CMPT Topic: Classes

this Pointer, Constant Functions, Static Data Members, and Static Member Functions this Pointer (11.1) Example of this pointer

Cpt S 122 Data Structures. Introduction to C++ Part II

Introduction to C++ Systems Programming


CS3157: Advanced Programming. Outline

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

Chapter 11: More About Classes and Object-Oriented Programming

16. Structs and Classes I

Fast Introduction to Object Oriented Programming and C++

Object-Oriented Design (OOD) and C++

Due Date: See Blackboard

UEE1303(1070) S 12 Object-Oriented Programming in C++

Intermediate Programming & Design (C++) Classes in C++

Abstract Data Types (ADT) and C++ Classes

Outline. User-dened types Categories. Constructors. Constructors. 4. Classes. Concrete classes. Default constructor. Default constructor

OBJECT ORIENTED PROGRAMMING USING C++

Linked List using a Sentinel

Object Oriented Programming

Lecture 8: Object-Oriented Programming (OOP) EE3490E: Programming S1 2017/2018 Dr. Đào Trung Kiên Hanoi Univ. of Science and Technology

7.1 Optional Parameters

Introduction to C++ (Extensions to C)

File I/O Christian Schumacher, Info1 D-MAVT 2013

Lecture 3 ADT and C++ Classes (II)

More class design with C++ Starting Savitch Chap. 11

Special Member Functions. Compiler-Generated Destructor. Compiler-Generated Default Constructor. Special Member Functions

Chapter 2. Procedural Programming

Programming Languages: OO Paradigm, Objects

Lecture 8. Xiaoguang Wang. February 13th, 2014 STAT 598W. (STAT 598W) Lecture 8 1 / 47

Outline. 1 Function calls and parameter passing. 2 Pointers, arrays, and references. 5 Declarations, scope, and lifetimes 6 I/O

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program:

Object Oriented Programming COP3330 / CGS5409

Recharge (int, int, int); //constructor declared void disply();

Programming C++ Lecture 3. Howest, Fall 2012 Instructor: Dr. Jennifer B. Sartor

Transcription:

A <Basic> 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 multi paradigmes 2

Declaration / definition of member-functions A member-function declaration is given within the class definition class Rational { private: int _num; // numerator int _denom; // denominator public: int get_num() const; int get_denom() const; void set_num(const int newnum); void set_denom(const int newdenom); //... ; Rational.h Programmation multi paradigmes 3

Declaration / definition of member-functions A member-function declaration is given within the class definition class Rational { private: int _num; // numerator int _denom; // denominator public: int get_num() const; int get_denom() const; void set_num(const int newnum); void set_denom(const int newdenom); //... ; A class defines a name scope Rational.h Programmation multi paradigmes 4

Declaration / definition of member-functions A member-function declaration is given within the class definition class Rational { private: int _num; // numerator int _denom; // denominator public: A prototype with a const suffix int get_num() const; indicates that the member-function int get_denom() const; does not modify its instance argument void set_num(const int newnum); void set_denom(const int newdenom); //... ; Rational.h Programmation multi paradigmes 5

Declaration / definition of member-functions A member-function declaration is given within the class definition class Rational { private: int _num; // numerator int _denom; // denominator public: int get_num() const; int get_denom() const; void set_num(const int newnum); void set_denom(const int newdenom); //... ; A parameter with a const prefix indicates that the parameter is in read only inside the associated function Rational.h Programmation multi paradigmes 6

Declaration / definition of member-functions A member-function definition is given outside the class definition int Rational::get_num() const{ return _num; int Rational::get_denom() const{ return _denom; void Rational::set_num(const int newnum){ _num = newnum; return; void Rational::set_denom(const int newdenom){ _denom = newdenom; return; Rational.cpp Programmation multi paradigmes 7

Declaration / definition of member-functions A member-function definition is given outside the class definition int Rational::get_num() const{ These functions are member return _num; functions so their qualified named are required int Rational::get_denom() const{ return _denom; void Rational::set_num(const int newnum){ _num = newnum; return; void Rational::set_denom(const int newdenom){ _denom = newdenom; return; Rational.cpp Programmation multi paradigmes 8

Declaration / definition of member-functions A member-function definition is given outside the class definition int Rational::get_num() const{ return _num; int Rational::get_denom() const{ return _denom; void Rational::set_num(const int newnum){ _num = newnum; We should check that return; newdenom is different from 0 void Rational::set_denom(const int newdenom){ _denom = newdenom; return; Rational.cpp Programmation multi paradigmes 9

Declaration / definition of member-functions A member-function can only be called through a class instance (selection operator.) int main() { Rational arationalobject = 2; arationalobject.set_num(6); //a call to a member function return 0; main.cpp Programmation multi paradigmes 10

Declaration / definition of member-functions A member-function can only be called through a class instance (selection operator. Or -> if pointer) int main() { Rational arationalobject = 2; Rational * arationalobjectpointer = &arationalobject; arationalobject.set_num(6); //a call to a member function arationalobjectpointer->set_num(6); // same than the previous line return 0; main.cpp Programmation multi paradigmes 11

Inline definition of member-functions A member-function body may be given within the class definition class Rational { private: int _num; // numerator int _denom; // denominator public: int get_num() const { return _num; int get_denom() const { return _denom; //... ; Rational.h Then the member-function is implicitly inline Programmation multi paradigmes 12

Inline definition of member-functions A member-function body may be given within the class definition class Rational { private: int _num; // numerator int _denom; // denominator public: int get_num() const { return _num; Inline means that function calls may int get_denom() const be replaced by the textual expansion { return _denom; of its body instead of generating a function call sequence //... ; Rational.h Then the member-function is implicitly inline Programmation multi paradigmes 13

Inline definition of member-functions Inline means that function calls may inline int Rational::get_num() const{ be replaced by the textual expansion return _num; of its body instead of generating a function call sequence inline int Rational::get_denom() const{ return _denom; Rational.cpp void Rational::set_num(const int newnum){ _num = newnum; return; void Rational::set_denom(const int newdenom){ _denom = newdenom; return; Rational.cpp Programmation multi paradigmes 14

This Week A little reminder Constructor / destructor Operator overloading Programmation multi paradigmes 15

Constructors Initialization constructor Initialize the value with the given parameters (or the default parameters) If necessary, allocate the required memory MyClass(parameterType aparam = defaultvalue); Copy constructor Initialize the value with the one of the object given If necessary, allocate the required memory MyClass(const MyClass &); Programmation multi paradigmes 16

Constructors Initialization constructor Initialize the value with the given parameters (or the default parameters) If necessary, allocate the required memory MyClass(parameterType aparam = defaultvalue); Almost every time called automatically by the compiler Copy constructor Initialize the value with the one of the object given If necessary, allocate the required memory MyClass(const MyClass &); Called when an object is created and initialized with another object of the same type + when at the beginning of a function call with a copy paradigm Programmation multi paradigmes 17

Constructors Initialization constructor Initialize the value with the given parameters (or the default parameters) If necessary, allocate the required memory MyClass(parameterType aparam = defaultvalue); Copy constructor Initialize the value with the one of the object given If necessary, allocate the required memory MyClass(const MyClass &); If the copy constructor is private, you forbid using copy during any function call: void f (MyClass c); void f (MyClass& c); //KO //OK Programmation multi paradigmes 18

Destructor Destructor Release the memory that has been previously allocated ~MyClass(); Almost every time called automatically by the compiler An object is destroyed at the end of the block in which it was created unless the memory allocation has been explicit (i.e. except a call to new) Programmation multi paradigmes 19

Constructor & Conversions of objects A one argument constructor defines an implicit conversion from the argument type to the class type The following are all equivalent Rational r = 3; Rational r = (Rational)3; Rational r(3); Rational r {3; //C++11 In all cases there is one constructor call, Rational(int) Programmation multi paradigmes 20

Constructor & Conversions of objects Implicit conversions in the other direction can also be defined Class Rational( public: operator double();; Rational::operator double() const { return (double)_num/ (double)_denom; //... double x = r; //... x = 3.0 + r; x = 3.0 + static_cast<double>(r); x = 3.0 + double(r); In all cases, a call to Rational::operator double() is made Programmation multi paradigmes 21

Constructor & Conversions of objects Implicit conversions in the other direction can also be defined Class Rational( public: operator double();; Rational::operator double() const { return (double)_num/ (double)_denom; //... double x = r; //... x = 3.0 + r; x = 3.0 + static_cast<double>(r); x = 3.0 + double(r); This is an operator overload! In all cases, a call to Rational::Operator double() is made Programmation multi paradigmes 22

Constructor & Conversions of objects Explicit conversions in the other direction can also be defined //C++11 Class Rational( public: explicit operator double();; Rational::operator double() const { return (double)_num/ (double)_denom; //... double x = r; //KO //... x = 3.0 + r; //KO x = 3.0 + static_cast<double>(r); //OK x = 3.0 + double(r); //OK Accept only explicit conversion! Programmation multi paradigmes 23

Constructor & Conversions of objects Implicit conversions in the other direction can also be defined Rational::operator MaClass() const { return MaClass(_num*_denom); //... Rational r ; //... MaClass mc = static_cast<maclass>(r) ; a call to Rational::operator MaClass() is made if no conversion constructor exists Programmation multi paradigmes 24

copy of objects (remember) Two cases where an object is copied : 1. Initializing a Rational from an other Rational Rational r = {3, 2; // (3/2) Rational r1 {r; Rational r2(r); f(r); //sometimes! 2. Assigning a Rational to an other Rational Rational r(3, 2), r1(3, 4); r1 = r; Programmation multi paradigmes 25

copy of objects (remember) Two cases where an object is copied: 1. Initializing a Rational from an other Rational Rational r = {3, 2; // (3/2) Rational r1 {r; Rational r2(r); f(r); //sometimes! 2. Assigning a Rational to an other Rational Rational r(3, 2), r1(3, 4); r1 = r; In both cases, default is memberwise (here bitwise) copy of underlying C structures Programmation multi paradigmes 26

Class Rational Member-function call Two cases where an object is copied: 1. Initializing a Rational from an other Rational Rational r = {3, 2; // (3/2) Rational r1 {r; Rational r2(r); f(r); //sometimes! 2. Assigning a Rational to an other Rational Rational r(3, 2), r1(3, 4); r1 = r; This is an assignment (and not a construction) Depends on the assignment operator implementation... Programmation multi paradigmes 28

copy of objects (remember) Two cases where an object is copied: 1. Initializing a Rational from an other Rational Rational r = {3, 2; // (3/2) Rational r1 {r; Rational r2(r); f(r); //sometimes! Copy Constructor 2. Assigning a Rational to an other Rational Rational r(3, 2), r1(3, 4); r1 = r; Assignment operator In both cases, default is memberwise (here bitwise) copy of underlying C structures Programmation multi paradigmes 29

copy of objects (remember) Two cases where an object is copied: 1. Initializing a Rational from an other Rational Rational r = {3, 2; // (3/2) Rational r1 {r; Rational r2(r); f(r); //sometimes! Copy Constructor 2. Assigning a Rational to an other Rational Rational r(3, 2), r1(3, 4); r1 = r; Assignment operator In both cases, default is memberwise (here bitwise) copy of underlying C structures A default operator is generated for the assignment operator but it is not true for all of them... Programmation multi paradigmes 30

Operator overloading Operator overloading is a way to realize classical arithmetic operation in a more readable and natural way: Rational r1(3, 2), r2; r1.add(r2) r1 + r2 r1.multiply(r2) r1 * r2 An operator overload can be of two kinds: 1. As a member function Identical to other member functions but with imposed name and number of parameters 2. As a friend function A friend function is a classical (non member or member of another class) function A friend function has privilege (access to the private attributes of a Class with which it is friend) Programmation multi paradigmes 31

Operator overloading Definition as a member function The assignment operator: Rational& Rational::operator=(const Rational& r){ _num = r.num; _denom = r.denom return *this; Usage Rational r {3, 2; Rational r1 {4, 5; r = r1; r.operator=(r1) //same than the previous line Programmation multi paradigmes 32

Operator overloading Definition as a member function The minus unary operator: Rational Rational::operator-() const { return Rational(-_num, _denom); Usage Rational r(3, 2); Rational r1 = -r; Rational r1bis = r.operator-() //same than the previous line r = -r1; r = r1.operator-() //same than the previous line Programmation multi paradigmes 33

Operator overloading Definition as a member function The multiply binary operator: Rational Rational::operator*(Rational r) const { return Rational(_num*r._num, _denom*r._denom); Usage Rational r{3, 2, r1{4, 3; Rational r2 = r * r1; Rational r2bis = r.operator*(r1) //same than the previous line r2 = r * r1; r2bis = r.operator*(r1) //same than the previous line Programmation multi paradigmes 34

Operator overloading Definition as a member function The multiply binary operator: Usage Rational Rational::operator*(Rational r) const { return Rational(_num*r._num, _denom*r._denom); Note that the access control is on a per class basis and not on a per instance basis Rational r{3, 2, r1{4, 3; Rational r2 = r * r1; Rational r2bis = r.operator*(r1) //same than the previous line r2 = r * r1; r2bis = r.operator*(r1) //same than the previous line Programmation multi paradigmes 35

Operator overloading Definition as a member function The multiply binary operator: Rational Rational::operator*(Rational r) const { return Rational(_num*r._num, _denom*r._denom); Usage Rational r{3, 2, r1{4, 3; Rational r2 = r * r1; Rational r2bis = r.operator*(r1) //same than the previous line r2 = r * 3; r2bis = r.operator*(rational(3)) //same than the previous line r2 = 3 * r1; //?? r2bis = 3.operator*(r1); //?? Programmation multi paradigmes 36

Operator overloading Definition as a member function The multiply binary operator: Rational Rational::operator*(Rational r) const { return Rational(_num*r._num, _denom*r._denom); Usage r2 = 3 * r1; //?? r2bis = 3.operator*(r1); //?? Problems: 1. The primitive types are not classes (no selection operator) 2. The int class designer can not anticipated the creation of new classes 3. No implicit conversion on the hidden argument of a member function Programmation multi paradigmes 37

Operator overloading Definition as a friend function The multiply binary operator: Rational friend operator*(rational r1, Rational r2) const { return Rational(r1._num * r2._num, _r1.denom * r2._denom); Usage Rational r(3, 2), r1(4, 3); Rational r2 = r * r1; Rational r2bis = operator*(r, r1) //same than the previous line r2 = r * 3; r2bis = operator*(r, Rational(3)) //same than the previous line r2 = 3 * r1; r2bis = operator*(rational(3), r1); //same than the previous line Programmation multi paradigmes 38

Operator overloading Definition as a friend function The multiply binary operator: Rational friend operator*(rational r1, Rational r2) const { return Rational(r1._num * r2._num, _r1.denom * r2._denom); Usage Rational r(3, 2), r1(4, 3); Rational r2 = r * r1; Using friend functions restore the symmetry (no more hidden parameters) Rational r2bis = operator*(r, r1) //same than the previous line r2 = r * 3; r2bis = operator*(r, Rational(3)) //same than the previous line r2 = 3 * r1; r2bis = operator*(rational(3), r1); //same than the previous line Programmation multi paradigmes 39

Operator overloading friend or member? For some of them, there is no choice, they must be members: = [ ] ( ) They always represents an asymmetric operation -> For the others, one may choose according to: Stylistic consideration num(r) vs r.num( )? Symmetry considerations Taking opportunity of implicit conversions? Programmation multi paradigmes 40

Printing an object Using a member-function (or a friend) #include <iostream> using namespace std; void Rational::print() { cout << _num << / << _denom); Rational r(3, 2); r.print(); // stdout --> 3/2 Programmation multi paradigmes 41

Printing an object Using IO streams Programmation multi paradigmes 42

Printing an object Using output streams #include <iostream> using namespace std; class Rational { //... friend ostream& operator<<(ostream&, Rational); //... ; Object you want to print Programmation multi paradigmes 43

Printing an object Using output streams #include <iostream> using namespace std; class Rational { //... friend ostream& operator<<(ostream&, Rational &); //... ; Reference on the object you want to print (to avoid copy of possibly large object) Programmation multi paradigmes 44

Printing an object Using output streams #include <iostream> using namespace std; class Rational { //... friend ostream& operator<<(ostream&, const Rational &); //... ; Constant Reference on the object you want to print (because a print is not intended to modify the object) Programmation multi paradigmes 45

Printing an object Using output streams #include <iostream> using namespace std; class Rational { //... friend ostream& operator<<(ostream&, const Rational &); //... ; Reference on an output flow (often the same object modified in the definition of the function) Constant Reference on the object you want to print (because a print is not intended to modify the object) Programmation multi paradigmes 46

Printing an object Using output streams #include <iostream> using namespace std; class Rational { //... friend ostream& operator<<(ostream&, const Rational &); //... ; ostream& operator<<(ostream& os, const Rational & r) { os << r._num << / << r._denom; return os; Call to operator<< of int operator<<(os, r._num) Call to operator<< of char operator<<(os, '/') Call to operator<< of int operator<<(os, r._denom) Programmation multi paradigmes 47

Printing an object Using output streams #include <iostream> using namespace std; class Rational { //... friend ostream& operator<<(ostream&, const Rational &); //... ; ostream& operator<<(ostream& os, Rational r) { os << r._num << / << r._denom; return os; //... cout << "value of r = " << r << endl; This print newline and flush the internal stream buffer out Programmation multi paradigmes 48

Editing an object Using input streams #include <iostream> using namespace std; class Rational { //... friend istream& operator>>(istream&, Rational &); //... ; istream& operator>>(istream& is, Rational& r) { is >> r._num; cout << / is >> r._denom; return is; //... cout << "give the value of r " << endl; cin >> r; Programmation multi paradigmes 49

Editing an object Using input streams #include <iostream> using namespace std; class Rational { //... Why is there a reference? friend istream& operator>>(istream&, Rational &); //... ; istream& operator>>(istream& is, Rational& r) { is >> r._num; cout >> / is >> r._denom; return is; //... cout << "give the value of r " << endl; cin >> r; Programmation multi paradigmes 50

Editing an object Using input streams #include <iostream> using namespace std; class Rational { //... friend istream& operator>>(istream&, Rational &); //... ; istream& operator>>(istream& is, Rational& r) { is >> r._num; cout >> / is >> r._denom; return is; #include <fstream> cout << "give the value of r " << endl; cin >> r; ofstream myfile; //create an ofstream object myfile.open("example.txt"); //open example.txt myfile << "Writing this to a file.\n"; MyFile << r; //writing r to the file myfile.close(); //closing the file Programmation multi paradigmes 51

Editing an object Using input streams #include <iostream> using namespace std; class Rational { //... friend istream& operator>>(istream&, Rational &); //... ; istream& operator>>(istream& is, Rational& r) { is >> r._num; cout >> / is >> r._denom; return is; cout << "give the value of r " << endl; cin >> r; ofstream myfile; //create an ofstream object myfile.open("example.txt"); //open example.txt myfile << "Writing this to a file.\n"; MyFile << r; //writing r to the file Rational r2; MyFile >> r2; //reading r from the file MyFile.close(); Programmation multi paradigmes 52

Class Rational Full specification (1/2) class Rational { private: int _num; // numerator int _denom; // denominator public: // Exception classes class Bad_Denom {; class Bad_Format {; // Construction and conversions Rational(const Rational&); Rational(int n= 0, int d= 1); operator double() const; // Access functions int get_num() const; int get_denom() const; // Assignment operator Rational& operator=(const Rational&); // Arithmetic operators Rational operator+() const; // unary plus Rational operator-() const; // unary minus Programmation multi paradigmes 53

Class Rational Full specification (1/2) class Rational { private: int _num = 0; // numerator C++11 // denominator C++11 int _denom = 1; public: // Exception classes class Bad_Denom {; class Bad_Format {; // Construction and conversions Rational(const Rational&); Rational(int n= 0, int d= 1); operator double() const; // Access functions int get_num() const; int get_denom() const; // Assignment operator Rational& operator=(const Rational&); // Arithmetic operators Rational operator+() const; // unary plus Rational operator-() const; // unary minus Programmation multi paradigmes 54

Class Rational Full specification (2/2) // Arithmetic operators (cont.) friend Rational operator+(rational, Rational); friend Rational operator-(rational, Rational); friend Rational operator*(rational, Rational); friend Rational operator/(rational, Rational); // Relational operators friend bool operator==(rational, Rational); friend bool operator!=(rational, Rational); friend bool operator<(rational, Rational); friend bool operator<=(rational, Rational); friend bool operator>(rational, Rational); friend bool operator>=(rational, Rational); ; // IO operators friend ostream& operator<<(ostream&, const Rational &); friend istream& operator>>(istream&, Rational&); Programmation multi paradigmes 55