Structures, Classes and Objects Handling data and objects Unit - 03.

Slides:



Advertisements
Similar presentations
Starting Out with C++: Early Objects 5th Edition
Advertisements

 2006 Pearson Education, Inc. All rights reserved Midterm review Introduction to Classes and Objects.
Chapter Objectives You should be able to describe: Object-Based Programming Classes Constructors Examples Common Programming Errors.
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
1 Classes and Objects. 2 Outlines Class Definitions and Objects Member Functions Data Members –Get and Set functions –Constructors.
Review of C++ Programming Part II Sheng-Fang Huang.
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
Pointer Data Type and Pointer Variables
Data Structures Using C++ 2E Chapter 3 Pointers and Array-Based Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
Learners Support Publications Classes and Objects.
C++ Review (3) Structs, Classes, Data Abstraction.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
Chapter 10 Introduction to Classes
Data Structures Using C++ 2E Chapter 3 Pointers. Data Structures Using C++ 2E2 Objectives Learn about the pointer data type and pointer variables Explore.
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes.
C++ Class Members Class Definition – class Name – { – public: » constructor(s) » destructor » function members » data members – protected: » function members.
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
CSC241 Object-Oriented Programming (OOP) Lecture No. 4.
Structured Data and Classes Chapter 7. Combining Data into Structures Structure: C++ construct that allows multiple variables to be grouped together Structure.
More C++ Features True object initialisation
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
CPSC 252 The Big Three Page 1 The “Big Three” Every class that has data members pointing to dynamically allocated memory must implement these three methods:
1 Chapter Four Creating and Using Classes. 2 Objectives Learn about class concepts How to create a class from which objects can be instantiated Learn.
Chapter 9 Classes: A Deeper Look, Part I Part II.
Chapter 3 Part I. 3.1 Introduction Programs written in C ◦ All statements were located in function main Programs written in C++ ◦ Programs will consist.
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
1 CSC241: Object Oriented Programming Lecture No 02.
2 Objectives You should be able to describe: Object-Based Programming Classes Constructors Examples Common Programming Errors.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
1 Mr. Muhammad Hanif Lecturer Information Technology MBBS Campus Dadu University of SIndh.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 1.
CPS120: Introduction to Computer Science Lecture 16 Data Structures, OOP & Advanced Strings.
1 CSC241: Object Oriented Programming Lecture No 03.
Array in C++ / review. An array contains multiple objects of identical types stored sequentially in memory. The individual objects in an array, referred.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
Chapter 4: More Object Concepts. Objectives Understand blocks and scope Overload a method Avoid ambiguity Create and call constructors with parameters.
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
Learners Support Publications Constructors and Destructors.
Dynamic Memory Management & Static Class Members Lecture No 7 Object Oriented Programming COMSATS Institute of Information Technology.
Chapter 12: Pointers, Classes, Virtual Functions, Abstract Classes, and Lists.
Functions Modules in C++ are called functions and classes. Main reason to use functions is : – get aid in conceptual organization.
C++ Features Function Overloading Default Functions arguments Thinking about objects – relationship to classes Types of member functions Constructor and.
Constructors and Destructors
Pointer to an Object Can define a pointer to an object:
Procedural and Object-Oriented Programming
By Muhammad Waris Zargar
CSC241: Object Oriented Programming
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
Friend Class Friend Class A friend class can access private and protected members of other class in which it is declared as friend. It is sometimes useful.
Student Book An Introduction
Dr. Bhargavi Dept of CS CHRIST
Constructors and destructors
Constructors and Destructors
Classes and Objects.
Java Programming Language
Submitted By : Veenu Saini Lecturer (IT)
ENERGY 211 / CME 211 Lecture 17 October 29, 2008.
Class Circle { Float xc, yc, radius;
Functions Chapter No. 5.
Presentation transcript:

Structures, Classes and Objects Handling data and objects Unit - 03

Unit Introduction This unit covers structures, classes and objects

Unit Objectives After covering this unit you will understand… Structures Structures Classes Classes Static data and member functions Static data and member functions Differences between structures and classes Differences between structures and classes References References Friend functions and classes Friend functions and classes

Structures Following will be discussed in order to understand structures: Following will be discussed in order to understand structures: Declaration Declaration Definition Definition Using structures Using structures Nested structures Nested structures

Declaring Structures struct keyword is used for declaration struct keyword is used for declaration A structure is collection of variables and methods A structure is collection of variables and methods In a structure, variables can have different data types In a structure, variables can have different data types Can have private, protected and public access specifiers Can have private, protected and public access specifiers The default access specifier is public The default access specifier is public Semicolon “;” comes in the end to complete structure declaration Semicolon “;” comes in the end to complete structure declaration

Example: Declaring Structures #include #include struct SPart { private: private: int partType; // type of part, by default public int partType; // type of part, by default public public: public: float cost; // cost of part, be default public float cost; // cost of part, be default public int GetPartType() int GetPartType() { return partType; return partType; } }; // semicolon indicates end of declaration

Defining Structures With declaration With declaration A structure can be defined while declaring the structure A structure can be defined while declaring the structure Structure Tag (which is used to name the structure) is not required, if a structure variable is defined while declaring the structure Structure Tag (which is used to name the structure) is not required, if a structure variable is defined while declaring the structure Without declaration Without declaration Structures can be defined separately after declaration Structures can be defined separately after declaration

Example: Defining Structures // declaring and defining together struct // tag is not required here { int partType; // type of part int partType; // type of part float cost; // cost of part float cost; // cost of part } part; // declared and defined // declaring and defining separately struct SMachine // tag is required to define it separately { int machineType; // type of machine int machineType; // type of machine float cost;// cost of machine float cost;// cost of machine }; // declared only SMachine machine; // defined now

Using Structures Structure can be initialised either by: Structure can be initialised either by: putting values in it; or putting values in it; or assigning other structure of same type assigning other structure of same type A structure variable can be assigned to other if they are instance of same structure A structure variable can be assigned to other if they are instance of same structure Assigning different structure types (even though they have exactly the same data types) is not allowed and will generate an error Assigning different structure types (even though they have exactly the same data types) is not allowed and will generate an error

Using Structures (contd.) Structures are initialised using curly braces Structures are initialised using curly braces Dot (.) operator is used to access the variables Dot (.) operator is used to access the variables

Example: Using Structures // Initialising a structure variables # include # include struct SPart { int partType; // type of part int partType; // type of part float cost; // cost of part float cost; // cost of part}; void main() { SPart part1 = {12,23.56}; // Initializing variables SPart part1 = {12,23.56}; // Initializing variables SPart part2; SPart part2; part2 = part1; part2 = part1; part2.cost = 13.5f;// cost variable accessed part2.cost = 13.5f;// cost variable accessed}

Structures Structures Nesting can be to any level (nth level) Nesting can be to any level (nth level) Dot (.) operator is used to access the each inner level Dot (.) operator is used to access the each inner level When the inner most level is reached, the dot (.) operator will be used to access the variables and functions When the inner most level is reached, the dot (.) operator will be used to access the variables and functions

Example: Nested Structures // Example of Structure nesting # include # include struct SDistance { int feet; int feet; float inches; float inches;}; struct SRoom { SDistance length; SDistance length; SDistance width; SDistance width;};

Example: Nested Structures (contd.) void main() { SRoom dining = {{10,120},{10,120}} // Initializing SRoom dining = {{10,120},{10,120}} // Initializing SRoom study; SRoom study; study.length.feet = 10; // Assigning values study.length.feet = 10; // Assigning values study.length.inches = 120; study.length.inches = 120; study.width.feet = 10; study.width.feet = 10; study.width.inches = 120; study.width.inches = 120;}

Classes in C++ Following will be discussed in order to understand Classes in C++: Following will be discussed in order to understand Classes in C++: Classes and objects Classes and objects Access specifiers Access specifiers Member functions Member functions Constructors Constructors Destructors Destructors Static class data Static class data

Classes and Objects Classes are the infrastructures while objects are runtime utilisation of those infrastructures Classes are the infrastructures while objects are runtime utilisation of those infrastructures A class has functions and data A class has functions and data Member functions and data can be of type private, public or protected Member functions and data can be of type private, public or protected Default access specifier is private Default access specifier is private Variables cannot be initialised during declaration (as you can in Java) Variables cannot be initialised during declaration (as you can in Java)

Example: A Simple Class Example: A Simple Class // demonstrates an object #include #include class SmallObj // Specify a class name { private: private: int m_SomeData; // Class data int m_SomeData; // Class data public: public: void SetData(int data) // member function to set data void SetData(int data) // member function to set data { m_SomeData = data; m_SomeData = data; } void ShowData() // member function to display data void ShowData() // member function to display data { cout << “\nData is “ << m_SomeData; cout << “\nData is “ << m_SomeData; }};

Example: A Simple Class (contd.) void main() { SmallObj s1, s2; // defining two objects SmallObj s1, s2; // defining two objects s1.SetData(1234); // calling member function to set data s1.SetData(1234); // calling member function to set data s2.SetData(5677); s2.SetData(5677); s1.ShowData(); // calling member function to display s1.ShowData(); // calling member function to display // data // data s2.ShowData(); s2.ShowData();}

Constructors Constructor is a class method with exactly the same name as class name Constructor is a class method with exactly the same name as class name A constructor may accept argument(s) but does not return anything, not even void A constructor may accept argument(s) but does not return anything, not even void They are called when an instance of the class is created They are called when an instance of the class is created A default constructor does not accept any argument A default constructor does not accept any argument

Constructors (contd.) If a default constructor is not provided, compiler assumes there exists but it does not do anything If a default constructor is not provided, compiler assumes there exists but it does not do anything Constructors can be overloaded in their argument type and number of arguments Constructors can be overloaded in their argument type and number of arguments In constructors, variables can be initialised to a default value In constructors, variables can be initialised to a default value A copy constructor is used when objects are copied A copy constructor is used when objects are copied

Example: Constructors #include #include class Customer // Specify a class name { private: private: int m_CustomerId; // Class data int m_CustomerId; // Class data public: public: Customer() // no-arg or default constructor Customer() // no-arg or default constructor { m_CustomerId = 0; // default customer ID m_CustomerId = 0; // default customer ID } Customer(int newCustomerId) // one-arg constructor Customer(int newCustomerId) // one-arg constructor { m_CustomerId = newCustomerId; m_CustomerId = newCustomerId; }};

Example: Constructors void main() { Customer ordinaryCustomer; // creating instance using Customer ordinaryCustomer; // creating instance using // default constructor // default constructor Customer registeredCustomer(49); // creating instance Customer registeredCustomer(49); // creating instance // using one-arg constructor // using one-arg constructor}

Copy Constructor Copy constructor is used when objects are copied Copy constructor is used when objects are copied Default copy constructor performs shallow copy Default copy constructor performs shallow copy Explicit copy constructor can be provided to perform deep copy Explicit copy constructor can be provided to perform deep copy

Shallow and Deep Copy m_pAddress name : e1 City : LHR State : Punjab Country : PK Address m_pAddress name : e1 City : LHR State : Punjab Country : PK Address m_pAddress name : e1 City : LHR State : Punjab Country : PK Address m_pAddress name : e2 City : LHR State : Punjab Country : PK Address m_pAddress name : e2 InitiallyShallow CopyDeep Copy EmployeeEmployee Employee Employee Employee

Example: Copy Constructor struct SAddress { char* city; char* city; char* state; char* state; char* country; char* country; SAddress() SAddress() { city = ""; city = ""; state = ""; state = ""; country = ""; country = ""; } void DisplayAddress() void DisplayAddress() { cout << city << ", " << state << ", " << country << endl; cout << city << ", " << state << ", " << country << endl; }};

Example: Copy Constructor (contd.) class Employee { private: private: SAddress* m_pAddress; SAddress* m_pAddress; char* m_Name; char* m_Name; public: public: Employee() Employee() { m_pAddress = 0; m_pAddress = 0; } ~Employee() ~Employee() { delete m_pAddress; delete m_pAddress; }

Example: Copy Constructor (contd.) void SetAddress(char* city, char* state, void SetAddress(char* city, char* state, char* country) char* country) { m_pAddress = new SAddress(); m_pAddress = new SAddress(); m_pAddress->city = city; m_pAddress->city = city; m_pAddress->state = state; m_pAddress->state = state; m_pAddress->country = country; m_pAddress->country = country; } SAddress* GetAddress() SAddress* GetAddress() { return m_pAddress; return m_pAddress; } void SetName(char* name) void SetName(char* name) { m_Name = name; m_Name = name; }

Example: Copy Constructor (contd.) char* GetName() char* GetName() { return m_Name; return m_Name; } void Display() void Display() { cout << m_Name << " -- "; cout << m_Name << " -- "; m_pAddress->DisplayAddress(); m_pAddress->DisplayAddress(); } // this copy constructor performs deep copy // this copy constructor performs deep copy Employee(Employee& e) Employee(Employee& e){ m_pAddress = new SAddress(); m_pAddress = new SAddress(); m_pAddress->city = e.GetAddress()->city; m_pAddress->city = e.GetAddress()->city; m_pAddress->state = e.GetAddress()->state; m_pAddress->state = e.GetAddress()->state; m_pAddress->country = e.GetAddress()->country; m_pAddress->country = e.GetAddress()->country; }};

Example: Copy Constructor (contd.) void main() { Employee e1;// no-arg constructor is called Employee e1;// no-arg constructor is called e1.SetName("E1"); e1.SetName("E1"); e1.SetAddress("LHR", "Punjab", "PK"); e1.SetAddress("LHR", "Punjab", "PK"); e1.Display(); e1.Display(); Employee e2 = e1; // copy constructor is called Employee e2 = e1; // copy constructor is called e2.SetName("E2"); e2.SetName("E2"); e2.GetAddress()->city = ”ISB";// change city for e2 e2.GetAddress()->city = ”ISB";// change city for e2 e1.Display(); e1.Display(); e2.Display(); e2.Display();}

Destructors Called when an instance of the class is destroyed Called when an instance of the class is destroyed Destructor is a class method starting with tilde (~) and have exactly the same name as class name Destructor is a class method starting with tilde (~) and have exactly the same name as class name Destructors are used to release resources held by the instance (object) Destructors are used to release resources held by the instance (object) Destructor does not accept any argument Destructor does not accept any argument

Destructors (contd.) Destructor does not return anything, not even void Destructor does not return anything, not even void Destructors can not be overloaded Destructors can not be overloaded Memory allocated by the instance is released after calling the destructor Memory allocated by the instance is released after calling the destructor Automatically called when the object goes out of scope Automatically called when the object goes out of scope

Example: Destructors #include #include class MyFileHandler { private: private: ofstream m_file; ofstream m_file; public: public: MyFileHandler() MyFileHandler() { m_file.open(“myFile.txt”, ios::binary); m_file.open(“myFile.txt”, ios::binary); } ~MyFileHandler() ~MyFileHandler() { m_file.close; m_file.close; }

Example: Destructors (contd.) void WriteToFile(int buff[1000]) void WriteToFile(int buff[1000]) { m_file.write((char*)buff, 1000*sizeof(int)); m_file.write((char*)buff, 1000*sizeof(int)); }}; void main() { int myData[1000]; int myData[1000]; MyFileHandler myFileHandler; MyFileHandler myFileHandler; for(int j=0; j < 1000; j++) for(int j=0; j < 1000; j++) { myData[j] = j; myData[j] = j; } myFilehandler.WriteToFile(myData); myFilehandler.WriteToFile(myData);} // as myFileHandler goes out of scope, destructor is called // and the file is closed

Member Functions Member functions are methods of a class, could be: Member functions are methods of a class, could be: private, private, protected or protected or public public Can be declared and defined together or separately Can be declared and defined together or separately Inline function’s code is expanded where it is called and differ in normal function calling mechanism Inline function’s code is expanded where it is called and differ in normal function calling mechanism

Example: Member Functions #include #include class Employee // Specify a class { private: private: int m_EmployeeId; // Class data int m_EmployeeId; // Class data int m_EmployeeAge; int m_EmployeeAge; protected: protected: // implicit inline function // implicit inline function void ShowAge() // Member function to show void ShowAge() // Member function to show { // Employee age { // Employee age cout << “\nAge is “ << m_EmployeeAge; cout << “\nAge is “ << m_EmployeeAge; }

Example: Member Functions (contd.) public: public: void SetId(int id) // Member function to set id void SetId(int id) // Member function to set id { m_EmployeeId = id; m_EmployeeId = id; } void ShowId(); // Declaration only void ShowId(); // Declaration only void SetAge(int age); // Declaration only void SetAge(int age); // Declaration only}; void Employee::ShowId() { cout << “\nId is “ << m_EmployeeId; cout << “\nId is “ << m_EmployeeId;} // explicit inline function inline void Employee::SetAge(int age) { m_EmployeeAge = age; m_EmployeeAge = age;}

Example: Member Functions (contd.) void main() { Employee manager, worker; // defining two objects Employee manager, worker; // defining two objects manager.SetId(1001); // calling member function to manager.SetId(1001); // calling member function to // set Id // set Id worker.SetId(5001); // calling member function to worker.SetId(5001); // calling member function to // set Id // set Id manager.SetAge(45); // calling member function to set manager.SetAge(45); // calling member function to set // manger’s age // manger’s age wroker.SetAge(45); // calling member function to set wroker.SetAge(45); // calling member function to set // worker’s age // worker’s age}

Static Data Static data could be any type Static data could be any type Also called class data Also called class data Lifetime is the entire program Lifetime is the entire program Shared among all objects of the same class Shared among all objects of the same class Static data members are accessed using class name and :: operator Static data members are accessed using class name and :: operator In C++ static data is declared inside the class and defined outside the class In C++ static data is declared inside the class and defined outside the class

Example: Static Data class Counter // Specify a class { private: private: int m_Count; // class data int m_Count; // class data public: public: void IncrementCount() void IncrementCount() { m_Count++; m_Count++; } int GetTotalCount() int GetTotalCount() { return m_Count; return m_Count; } Counter() Counter() { m_Count = 0; m_Count = 0; } }; };

Example: Static Data (contd.) class Student { private: private: int m_StudentId; // class data int m_StudentId; // class data int m_StudentClass; int m_StudentClass; static Counter sm_Counter; // static counter to hold // count for all students static Counter sm_Counter; // static counter to hold // count for all students public: public: void AddStudent(int id,int studentClass) void AddStudent(int id,int studentClass) { m_StudentId = id; m_StudentId = id; m_StudentClass= studentClass; m_StudentClass= studentClass; sm_Counter.IncrementCount(); // increment count sm_Counter.IncrementCount(); // increment count } int GetStudentsCount() // getting class id int GetStudentsCount() // getting class id { return sm_Counter.GetTotalCount(); return sm_Counter.GetTotalCount(); }

Example: Static Data (contd.) }; Counter Student::sm_Counter; // if we don’t write this line // compiler will give error void main() { Student newStudent; Student newStudent; Student oldStudent; Student oldStudent; newStudent.AddStudent(100,10); newStudent.AddStudent(100,10); oldStudent.AddStudent(23,10); oldStudent.AddStudent(23,10); cout << “\nTotal = “ << oldStudent.GetStudentsCount(); cout << “\nTotal = “ << oldStudent.GetStudentsCount();}

Difference Between Structures and Classes The default access specifier in class is private, whereas in structure it is public The default access specifier in class is private, whereas in structure it is public Structures are inherited as public by default Structures are inherited as public by default Classes are inherited as private by default Classes are inherited as private by default

References Available only in C++, not in C Available only in C++, not in C One way to pass parameters to function is by reference One way to pass parameters to function is by reference The variable passed by reference, if altered, changes the actual variable value The variable passed by reference, if altered, changes the actual variable value & is used to denote a reference, e.g. &p (where p is any data type) & is used to denote a reference, e.g. &p (where p is any data type) References could be constant, called constant references, e.g. const &p References could be constant, called constant references, e.g. const &p

Example: References // Passing by reference example #include #include void main() { void IntFrac(const float&, float&, float&); void IntFrac(const float&, float&, float&); float number,intPart,fracPart; float number,intPart,fracPart; do do { cout << “\nEnter a real number:”; cout << “\nEnter a real number:”; cin >> number; cin >> number; Intfrac(number,intPart,fracPart); Intfrac(number,intPart,fracPart); cout << “Integer part is “ << intPart cout << “Integer part is “ << intPart << “, fraction part is “ << fracPart; << “, fraction part is “ << fracPart; }while (number != 0) }while (number != 0)}

Example: References (contd.) //IntFrac() // finds integer and fractional part of the real number void IntFrac(const float& n, float& intp, float& fracp) { intp = float(long(n)); intp = float(long(n)); fracp = n - intp; fracp = n - intp; // n can not be changed inside the function as it is // constant reference }

Friend Classes and Functions There are two types of friend modifiers: There are two types of friend modifiers: Class Level Class Level Function Level Function Level A friend function can access the private data of that class A friend function can access the private data of that class A friend function does not belong to a class, and A friend function does not belong to a class, and Its definition occurs outside the class without specifying the class name Its definition occurs outside the class without specifying the class name

Example: Friend Function / Class // friend function example #include #include class Beta;// forward declaration of class Beta class Alpha { private: private: int m_Data; // class private data int m_Data; // class private data public; public; Alpha() Alpha(){ m_Data = 3; m_Data = 3; } // assigning class data } // assigning class data friend int FriFunc(Alpha,Beta); // declaring friend friend int FriFunc(Alpha,Beta); // declaring friend // function // function friend Beta; // Beta is friend of // Alpha // Alpha};

Example: Friend Function / Class (contd.) class Beta { private private int m_Data; // class private data int m_Data; // class private data public: public: Beta() Beta() { m_Data = 7; m_Data = 7; } // assigning data } // assigning data void ChangeAlpha(Alpha& a); void ChangeAlpha(Alpha& a); friend int FriFunc(Alpha,Beta); // declaraing friend friend int FriFunc(Alpha,Beta); // declaraing friend }; // function int FriFunc(Alpha a, Beta b)// friend function { return (a.m_Data + b.m_Data); return (a.m_Data + b.m_Data);}

Example: Friend Function / Class (contd.) void Beta::ChangeAlpha(Alpha& a) { a.m_Data = 100;// change Alpha’s private data // as Beta is a friend of Alpha a.m_Data = 100;// change Alpha’s private data // as Beta is a friend of Alpha} void main() { Alpha aa;// define aa Alpha aa;// define aa Beta bb;// define bb Beta bb;// define bb cout << FriFunc(aa,bb);// calling friend function cout << FriFunc(aa,bb);// calling friend function bb.ChangeAlpha(aa);// change Alpha’s private data // through bb bb.ChangeAlpha(aa);// change Alpha’s private data // through bb cout << FriFunc(aa,bb);// calling friend function cout << FriFunc(aa,bb);// calling friend function}

Unit Summary In this unit you have covered … In this unit you have covered … Structures Structures Classes Classes Static data and member functions Static data and member functions References References Friend functions and classes Friend functions and classes