The document discusses various C++ concepts including static class members, the this pointer, friend functions and classes, dynamic memory management using new and delete operators, function overloading, operator overloading, templates, and inheritance. Static class members are accessible to all objects of the class and only one copy is created for the entire class. The this pointer refers to the current object from within non-static member functions. Friend functions and classes can access private members of other classes. Dynamic memory is allocated using new and freed using delete.
C++ Object oriented concepts & programmingnirajmandaliya
油
This document discusses various C++ concepts related to functions and operators. It defines what a default pointer is and how it receives addresses passed to a called function. It also discusses reference variables, inline functions, friend functions, default arguments, passing objects as parameters, function overloading, static members, function pointers, and operator overloading. It provides examples and explanations for each concept.
C++ - Constructors,Destructors, Operator overloading and Type conversionHashni T
油
This document discusses constructors and destructors in C++. It begins by defining constructors as special methods that are automatically called when an object is created. Constructors initialize class data members and have the same name as the class. Destructors are used to destroy objects and clean up memory. The document then covers topics like parameterized constructors, copy constructors, dynamic constructors, characteristics of constructors and destructors, and operator overloading and type conversions.
This document discusses various C++ concepts related to functions including:
- Default pointers which receive addresses passed to called functions.
- Reference variables which receive the reference of an actual variable passed to a function. Changing the reference variable directly changes the actual variable.
- Inline functions which eliminate context switching when defined inside a class or declared with the inline keyword.
- Friend functions which have access to private/protected members of a class they are declared as a friend to.
Lecture-11 Friend Functions and inline functions.pptxrayanbabur
油
This document discusses various object-oriented programming concepts in C++ including friend functions, inline functions, the this pointer, and static members. Friend functions can access private members of a class but are not member functions themselves. Inline functions avoid code duplication. The this pointer refers to the invoking object inside member functions. Static members are shared across all class objects rather than each object having its own copy. The document provides examples to demonstrate how each concept works in C++ code.
The document discusses various C++ concepts including static class members and static member functions, the this pointer, friend functions, dynamic memory allocation using new and delete operators, function overloading and operator overloading, restrictions on operator overloading, type conversion, and templates and inheritance. It provides examples to illustrate concepts like static class members, friend functions, new and delete operators, function overloading, and operator overloading. The document serves as a reference for various advanced C++ programming concepts.
1. Inline functions are small functions whose code is inserted at the call site instead of generating a function call. This avoids overhead of function calls but increases code size.
2. Function overloading allows different functions to have the same name but different parameters. The compiler determines which version to call based on argument types.
3. C++ classes allow defining data types that bundle together data members and member functions that can access them. Classes support data hiding and inheritance.
This document discusses different types of functions in C++ including: library functions, user-defined functions, overloaded functions, inline functions, friend functions, static functions, constructor functions, destructor functions, and virtual functions. It provides examples and definitions for each type of function.
This document discusses key concepts of classes and objects in C++ including access specifiers, constructors, destructors, mutators and accessors, inline functions, polymorphism through operator and function overloading, static class members, friend functions and classes, inheritance, and virtual functions. It provides examples of how these concepts are implemented in C++ code.
The document discusses classes, objects, constructors, and other object-oriented programming concepts in C#:
1) A class defines the data and behavior of a type using variables, methods, and events. Objects are instances of classes that have identity, data, and behaviors defined by the class.
2) Constructors initialize objects and are called using the new keyword. Constructors can be overloaded, parameterized, static, or chained to call another constructor.
3) Classes support concepts like inheritance, hiding, overriding, and polymorphism to extend and customize behavior in derived classes. References and values can be passed into methods.
C/C++ Programming interview questions and answers document discusses key concepts in C++ including encapsulation, inheritance, polymorphism, constructors, destructors, copy constructors, references, virtual functions, abstract classes, and memory alignment. The document provides definitions and examples to explain each concept.
- Classes and objects allow programmers to bundle data and functions that work on that data together. A class defines the data and functions, while an object is an instance of a class.
- The main differences between classes and structures in C++ are that class members are private by default while structure members are public, and objects of classes can allow null values while objects of structures cannot.
- Constructors are special member functions that are called automatically when an object is created. They are used to initialize the data members of newly created objects. Constructors have the same name as the class but do not have a return type.
Class and Object
- A class is a user-defined data type that holds its own data members and member functions. An object is an instance of a class created using the class blueprint.
- When a class is defined, no memory is allocated but when an object is created, memory is allocated for that object.
- Classes use access specifiers like public, private, and protected to control access to members.
The document discusses structures and classes in C++. It explains that structures in C++ allow grouping of related data items but do not provide data hiding. Classes in C++ address this limitation by allowing data and functions as members, and designating some members as private. The key aspects of a class include its declaration with data and function members, creation of objects from the class, and accessing members using objects and dot operator (for public members) or within class functions (for private members). Static members are also discussed which are shared among all class objects.
Static Data Members and Member FunctionsMOHIT AGARWAL
油
Static data members and static member functions in C++ classes are shared by all objects of that class. Static data members are initialized to zero when the first object is created and shared across all instances, while static member functions can only access other static members and are called using the class name and scope resolution operator. The example program demonstrates a class with a static data member "count" that is incremented and accessed by multiple objects to assign increasing code values, and a static member function "showcount" that prints the shared count value.
This document discusses object-oriented programming concepts like abstraction, encapsulation, constructors, and destructors in C++. It defines abstraction as hiding unnecessary details from the user to simplify complexity. Encapsulation refers to binding data with the methods that operate on the data. Constructors are special member functions that are called automatically when an object is created to initialize it. Destructors are called when an object is destroyed to perform cleanup. The document also provides examples of implementing these concepts in C++ code.
The document discusses various object-oriented programming concepts in C++ like classes, objects, member functions, data members, constructors, destructors, friend functions, and namespaces. It provides examples of defining classes with data members and member functions, declaring objects of a class, and using constructors and destructors. It also explains concepts like overloaded constructors, copy constructors, nested classes, dynamic initialization of objects, and friend functions.
Example for Virtual and Pure Virtual function.pdfrajaratna4
油
Virtual functions allow functions to be overridden in derived classes. They are useful for runtime polymorphism. A pure virtual function is a virtual function in a base class that has no definition, serving as a placeholder that must be overridden in derived classes. Derived classes that override all pure virtual functions from their base classes can have objects instantiated.
- Constructors are special member functions that are used to initialize objects of a class. They are automatically called when an object is created.
- There are different types of constructors including default, parameterized, and copy constructors. Default constructors take no parameters while parameterized constructors allow passing initial values.
- Constructors can be explicitly or implicitly called. Implicit calls are made when an object is declared while explicit calls directly call the constructor. Constructors ensure objects are properly initialized.
This document discusses object-oriented programming concepts in C++ including classes, objects, constructors, destructors, and friend functions. It begins by explaining that classes are abstract data types that contain data members and member functions. It then provides examples of declaring a class, creating objects, and accessing class members. It also covers topics like static class members, arrays of objects, constructor and destructor definitions and uses, and declaring friend functions to allow non-member functions access to private class members.
This document discusses various concepts related to classes and objects in C++, including member functions, data members, constructors, destructors, friend functions, and nested classes. It provides examples of defining member functions inside and outside the class, different access specifiers for data members, examples of friend functions and classes, returning objects from functions, arrays of objects, and nested classes. It also discusses constructors in more detail, including overloaded constructors, copy constructors, dynamic initialization of objects, constructors for primitive types, and constructors with default arguments.
Salesforce is built on the Lightning Platform. This session will provide you with the same training that Salesforce engineers receive during on-boarding. We are bringing this training to you in a two part series. Part 1 will provide detailed information about Component Definition including component-based architecture, component structure, component implementation and key components.
How to Configure Flexible Working Schedule in Odoo 18 EmployeeCeline George
油
In this slide, well discuss on how to configure flexible working schedule in Odoo 18 Employee module. In Odoo 18, the Employee module offers powerful tools to configure and manage flexible working schedules tailored to your organization's needs.
1. Inline functions are small functions whose code is inserted at the call site instead of generating a function call. This avoids overhead of function calls but increases code size.
2. Function overloading allows different functions to have the same name but different parameters. The compiler determines which version to call based on argument types.
3. C++ classes allow defining data types that bundle together data members and member functions that can access them. Classes support data hiding and inheritance.
This document discusses different types of functions in C++ including: library functions, user-defined functions, overloaded functions, inline functions, friend functions, static functions, constructor functions, destructor functions, and virtual functions. It provides examples and definitions for each type of function.
This document discusses key concepts of classes and objects in C++ including access specifiers, constructors, destructors, mutators and accessors, inline functions, polymorphism through operator and function overloading, static class members, friend functions and classes, inheritance, and virtual functions. It provides examples of how these concepts are implemented in C++ code.
The document discusses classes, objects, constructors, and other object-oriented programming concepts in C#:
1) A class defines the data and behavior of a type using variables, methods, and events. Objects are instances of classes that have identity, data, and behaviors defined by the class.
2) Constructors initialize objects and are called using the new keyword. Constructors can be overloaded, parameterized, static, or chained to call another constructor.
3) Classes support concepts like inheritance, hiding, overriding, and polymorphism to extend and customize behavior in derived classes. References and values can be passed into methods.
C/C++ Programming interview questions and answers document discusses key concepts in C++ including encapsulation, inheritance, polymorphism, constructors, destructors, copy constructors, references, virtual functions, abstract classes, and memory alignment. The document provides definitions and examples to explain each concept.
- Classes and objects allow programmers to bundle data and functions that work on that data together. A class defines the data and functions, while an object is an instance of a class.
- The main differences between classes and structures in C++ are that class members are private by default while structure members are public, and objects of classes can allow null values while objects of structures cannot.
- Constructors are special member functions that are called automatically when an object is created. They are used to initialize the data members of newly created objects. Constructors have the same name as the class but do not have a return type.
Class and Object
- A class is a user-defined data type that holds its own data members and member functions. An object is an instance of a class created using the class blueprint.
- When a class is defined, no memory is allocated but when an object is created, memory is allocated for that object.
- Classes use access specifiers like public, private, and protected to control access to members.
The document discusses structures and classes in C++. It explains that structures in C++ allow grouping of related data items but do not provide data hiding. Classes in C++ address this limitation by allowing data and functions as members, and designating some members as private. The key aspects of a class include its declaration with data and function members, creation of objects from the class, and accessing members using objects and dot operator (for public members) or within class functions (for private members). Static members are also discussed which are shared among all class objects.
Static Data Members and Member FunctionsMOHIT AGARWAL
油
Static data members and static member functions in C++ classes are shared by all objects of that class. Static data members are initialized to zero when the first object is created and shared across all instances, while static member functions can only access other static members and are called using the class name and scope resolution operator. The example program demonstrates a class with a static data member "count" that is incremented and accessed by multiple objects to assign increasing code values, and a static member function "showcount" that prints the shared count value.
This document discusses object-oriented programming concepts like abstraction, encapsulation, constructors, and destructors in C++. It defines abstraction as hiding unnecessary details from the user to simplify complexity. Encapsulation refers to binding data with the methods that operate on the data. Constructors are special member functions that are called automatically when an object is created to initialize it. Destructors are called when an object is destroyed to perform cleanup. The document also provides examples of implementing these concepts in C++ code.
The document discusses various object-oriented programming concepts in C++ like classes, objects, member functions, data members, constructors, destructors, friend functions, and namespaces. It provides examples of defining classes with data members and member functions, declaring objects of a class, and using constructors and destructors. It also explains concepts like overloaded constructors, copy constructors, nested classes, dynamic initialization of objects, and friend functions.
Example for Virtual and Pure Virtual function.pdfrajaratna4
油
Virtual functions allow functions to be overridden in derived classes. They are useful for runtime polymorphism. A pure virtual function is a virtual function in a base class that has no definition, serving as a placeholder that must be overridden in derived classes. Derived classes that override all pure virtual functions from their base classes can have objects instantiated.
- Constructors are special member functions that are used to initialize objects of a class. They are automatically called when an object is created.
- There are different types of constructors including default, parameterized, and copy constructors. Default constructors take no parameters while parameterized constructors allow passing initial values.
- Constructors can be explicitly or implicitly called. Implicit calls are made when an object is declared while explicit calls directly call the constructor. Constructors ensure objects are properly initialized.
This document discusses object-oriented programming concepts in C++ including classes, objects, constructors, destructors, and friend functions. It begins by explaining that classes are abstract data types that contain data members and member functions. It then provides examples of declaring a class, creating objects, and accessing class members. It also covers topics like static class members, arrays of objects, constructor and destructor definitions and uses, and declaring friend functions to allow non-member functions access to private class members.
This document discusses various concepts related to classes and objects in C++, including member functions, data members, constructors, destructors, friend functions, and nested classes. It provides examples of defining member functions inside and outside the class, different access specifiers for data members, examples of friend functions and classes, returning objects from functions, arrays of objects, and nested classes. It also discusses constructors in more detail, including overloaded constructors, copy constructors, dynamic initialization of objects, constructors for primitive types, and constructors with default arguments.
Salesforce is built on the Lightning Platform. This session will provide you with the same training that Salesforce engineers receive during on-boarding. We are bringing this training to you in a two part series. Part 1 will provide detailed information about Component Definition including component-based architecture, component structure, component implementation and key components.
How to Configure Flexible Working Schedule in Odoo 18 EmployeeCeline George
油
In this slide, well discuss on how to configure flexible working schedule in Odoo 18 Employee module. In Odoo 18, the Employee module offers powerful tools to configure and manage flexible working schedules tailored to your organization's needs.
Information Technology for class X CBSE skill SubjectVEENAKSHI PATHAK
油
These questions are based on cbse booklet for 10th class information technology subject code 402. these questions are sufficient for exam for first lesion. This subject give benefit to students and good marks. if any student weak in one main subject it can replace with these marks.
Computer Application in Business (commerce)Sudar Sudar
油
The main objectives
1. To introduce the concept of computer and its various parts. 2. To explain the concept of data base management system and Management information system.
3. To provide insight about networking and basics of internet
Recall various terms of computer and its part
Understand the meaning of software, operating system, programming language and its features
Comparing Data Vs Information and its management system Understanding about various concepts of management information system
Explain about networking and elements based on internet
1. Recall the various concepts relating to computer and its various parts
2 Understand the meaning of softwares, operating system etc
3 Understanding the meaning and utility of database management system
4 Evaluate the various aspects of management information system
5 Generating more ideas regarding the use of internet for business purpose
QuickBooks Desktop to QuickBooks Online How to Make the MoveTechSoup
油
If you use QuickBooks Desktop and are stressing about moving to QuickBooks Online, in this webinar, get your questions answered and learn tips and tricks to make the process easier for you.
Key Questions:
* When is the best time to make the shift to QuickBooks Online?
* Will my current version of QuickBooks Desktop stop working?
* I have a really old version of QuickBooks. What should I do?
* I run my payroll in QuickBooks Desktop now. How is that affected?
*Does it bring over all my historical data? Are there things that don't come over?
* What are the main differences between QuickBooks Desktop and QuickBooks Online?
* And more
Prelims of Kaun TALHA : a Travel, Architecture, Lifestyle, Heritage and Activism quiz, organized by Conquiztadors, the Quiz society of Sri Venkateswara College under their annual quizzing fest El Dorado 2025.
Database population in Odoo 18 - Odoo slidesCeline George
油
In this slide, well discuss the database population in Odoo 18. In Odoo, performance analysis of the source code is more important. Database population is one of the methods used to analyze the performance of our code.
How to Setup WhatsApp in Odoo 17 - Odoo 際際滷sCeline George
油
Integrate WhatsApp into Odoo using the WhatsApp Business API or third-party modules to enhance communication. This integration enables automated messaging and customer interaction management within Odoo 17.
Useful environment methods in Odoo 18 - Odoo 際際滷sCeline George
油
In this slide well discuss on the useful environment methods in Odoo 18. In Odoo 18, environment methods play a crucial role in simplifying model interactions and enhancing data processing within the ORM framework.
Research & Research Methods: Basic Concepts and Types.pptxDr. Sarita Anand
油
This ppt has been made for the students pursuing PG in social science and humanities like M.Ed., M.A. (Education), Ph.D. Scholars. It will be also beneficial for the teachers and other faculty members interested in research and teaching research concepts.
SOCIAL CHANGE(a change in the institutional and normative structure of societ...DrNidhiAgarwal
油
This PPT is showing the effect of social changes in human life and it is very understandable to the students with easy language.in this contents are Itroduction, definition,Factors affecting social changes ,Main technological factors, Social change and stress , what is eustress and how social changes give impact of the human's life.
Digital Tools with AI for e-Content Development.pptxDr. Sarita Anand
油
This ppt is useful for not only for B.Ed., M.Ed., M.A. (Education) or any other PG level students or Ph.D. scholars but also for the school, college and university teachers who are interested to prepare an e-content with AI for their students and others.
How to Configure Restaurants in Odoo 17 Point of SaleCeline George
油
Odoo, a versatile and integrated business management software, excels with its robust Point of Sale (POS) module. This guide delves into the intricacies of configuring restaurants in Odoo 17 POS, unlocking numerous possibilities for streamlined operations and enhanced customer experiences.
How to Configure Restaurants in Odoo 17 Point of SaleCeline George
油
object oriented programming language.pptx
1. Defining Member Functions
The member function must be declared inside the class.
They can be defined in
a) private or public section
b) inside or outside the class.
The member functions defined inside the class are treated as inline function.
If the member function is small then it should be defined inside the classotherwise it
should be defined outside the class
2. Member function inside the class
Member function inside the class can be declared in public or private section
public member functions
WAP to define member function in public section.
#include<iostream.h>
class product
{
private:
int pno;
float p;
public:
void getdata() {
cout<< "enter the product no and price";
cin>>pno>>p; }
void show() { cout<<"product no="<<pno<<endl<<"price="<<p; }};
void main()
{
product x;
x.getdata();
x.show();
}
3. Private member functions
WAP to declare private member function and access it by using public member functions
#include<iostream.h>
class product
{
private:
int pno;
float p;
void getdata() {
cout<< "enter the product no and price";
cin>>pno>>p; }
public:
void show()
{
getdata();
cout<<"product no="<<pno<<endl<<"price="<<p;
}
};
void main()
{
product x;
x.show();
}
4. Member function outside the class
To define a function outside the class the following care must be taken:
1. The prototype of function must be declared inside the class.
2. The function name must be preceded by class name and its return
type separated by scope resolution operator denoted by ::
5. Continue.
WAP to define member function of class outside the class.
#include<iostream.h>
class product
{
private:
int pno;
float p;
public:
void getdata() {
cout<< "enter the product no and price";
cin>>pno>>p; }
void show();
};
void product:: show()
{
cout<<"product no="<<pno<<endl<<"price="<<p;
}
void main()
{
product x;
x.getdata();
x.show();
}
6. Characteristics of member functions
1. The difference between member and normal function is that the
normal function can be invoked freely where as the member
function only by using an object of the same class.
2. The private data or private function can be accessed by public
member function . Other functions have no access permission.
3. The member function can invoke one another without using any
object or dot operator.
7. Inline Functions
When a function is declared as inline, the compiler copies the code of
the function in the calling function i.e. function body is inserted in
place of function call during compilation.
Passing of control between caller and callee functions is avoided.
If the function is very large, in such a case inline function is not used
because compiler copies the contents in the called function that
reduces the program execution speed.
It is advisable to use inline function for only small function.
8. Continue
Following are some situations where inline function may not work:
1. The function should not be recursive.
2. Function should not contain static variables.
3. Functions containing control structure statements such as switch ,if,
for loop etc.
4. The function main() cannot work as inline.
9. Function Overloading
It is possible in c++ to use the same function name for a number of
times for different intentions.
Defining multiple functions with same name is known as function
overloading. The overloaded function must be different in its argument
list and with different data types
10. Example
WAP to find the area of rectangle, square, triangle .use function
overloading.
11. Static member variables
Once a data member variable is declared as static, only one copy of
that member is created for the whole class.
For ex: static int a;
int A::a=0; where A is the class name
The class and scope of the static variable is defined outside the class
declaration. The reason are:
The static data members are associated with the class and not with
any object.
The static data member variable are stored individually rather than an
element of an object.
It must be initialized otherwise the linker will generate an error.
The memory for static data is allocated only once.
Only one copy of static member variable is created for the whole class
for any number of objects.
12. Static member functions
When a function is defined as static , it can access only static member
variables and functions of the same class. The static keyword makes the
function free form the individual object of the class and its scope is global in
the class without creating any side effect for other part of the program.
The programmer must follow the following points while declaring static
function:
1. Just one copy of static member is created in the memory for entire class.
2. Static member functions can access only static data members or functions.
3. Static member functions can be invoked using class name.
4. It is also possible to invoke static member functions using objects.
5. When one of the objects changes the value of data member variables, the
effect is visible to all the objects of the class.
13. Continue..
WAP to declare static member functions.
Class A
{
static int c;
public:
static void count(){ c++;}
static void display()
{
cout<<n value of c:<<c;
}
};
int A::c=0;
void main()
{
A::count();
A:: count();
A::display();
}
14. Friend Functions
C++ allows a mechanism, in which a non-member function has access
permission to the private members of the class. This can be done by declaring a
non-member function friend to the class whose private data is to be accessed.
Here friend is a keyword.
The friend functions have the following properties:
1. There is no scope restriction for the friend function hence they can be
called directly without using objects.
2. Unlike member functions of class, friend function cannot access the
member directly.
3. Use of friend functions is rarely done , because it violates the rule of
encapsulation and data hiding.
4. The function can be declared in public or private sections without changing
its meaning.
16. WAP to access private data using non-member function. Use friend
function.
17. Constructor
Constructor is a special member function that has the same name as that of
the class it belongs.
Constructor is executed when an object is declared.
It have neither return value nor void.
The main function of constructor is to initialize objects and allocate
appropriate memory space to objects.
Though constructors are executed implicitly , they can be invoked explicitly.
Constructors can have default and can be overloaded
18. An example of constructor:
class A
{
private: int a, b, c;
public:
A();
}
A::A()
{ a=0 ; b=0;c=0;}
void main()
{
A x;
}
21. Parametrized Constructor
It is also possible to create constructor with arguments and such
constructors are called as parameterized constructors. For such
constructor ,it is necessary to pass values to the constructor when
object is create
22. Continue..
WAP to create constructor with arguments and pass the arguments to the constructor.
#include<iostream.h>
class A
{
int a,b,c;
public: A(int i,int j,int k)
{
a=i ;b=j;c=k;
}
void show()
{
cout<<a=<<a<<b=<<b<<c=<<c;
}
};
void main()
{
A x=A(4,5,7) //explicit call
A y(1,2,8);
x.show();
y.show();
}
23. Copy Constructors
When we pass an object by value into a function, a temporary copy of
that object is created. All copy constructors requires one argument
with reference to an object of that class. Using copy constructors, it is
possible for the programmers to declare and initialize one object using
reference of another object.
24. Continue
WAP to demonstrate copy constructors.
#include<iostream.h>
class A
{
int n;
public: A(){}
A(int k)
{
n=k;
}
A(A &j)
{
n=j.n;
}
void show(){ cout<<n=<<n;}
};
void main()
{ A x(50);
A y(x);
x.show();
y.show();
}
25. Overloaded constructors
Like functions, it is also possible to overload constructors.
A class can contain more than one constructor. This is known as
constructor overloading.
All the constructors contain different no of arguments.
26. Destructors
It is also a special member function like constructor.
Destructors destroy the class objects created by constructors.
The destructors have the same name as their class, preceded by a tilde(~).
It is not possible to define more than one destructor.
The destructor is only way to destroy the object. Hence, they cannot be
overloaded.
A destructor neither requires any argument nor returns any value.
It is automatically called when object goes out of space. Destructor
release memory space occupied by the objects.
27. Continue
WAP to demonstrate execution of constructor and destructor.
class A
{
public:
A()
{
cout<<n constructor executed;
}
~A()
{
cout<<n destructor executed;
}
};
void main()
{
A x;
}
28. Continue
WAP to create an object and release them using destructors.
int c=0;
Class A
{
public: A()
{
c++;
cout<<n object created: object(<<c<<);
}
~A()
{
cout<<n object realeased: object(<<c<<);
}
};
void main()
{
A x,y,z;
}
29. Inheritance
It is the process by which one class acquire or inherit the properties of
another class. In other words, the mechanism of deriving a new class
from an old one is called inheritance.
The old class is referred as base class and the new one is called the
derived class.
where A is a base class and b is a derived class
A
B
31. Single Inheritance
A derived class with only one base class is known as single inheritance.
class A
{};
class B:public A
{};
Where A is a base class and B is a derived class
A
B
32. Multiple Inheritance
A derived class with several base classes is known as multiple inheritance.
class A
{};
class B
{};
class C: public A, public B
{};
Where A and B are base classes and C is derived class
A
C
B
33. Multilevel Inheritance
The mechanism of deriving a class from another derived class i.e derived class act as a base class is known as
Multilevel inheritance.
Class A
{};
Class B: public A
{};
Class C :public B
{};
Where A is base class and B is derived class
B is base class and C is derived class( derived class B act as a base class )
A
B
C
34. Hierarchical Inheritance
The traits of one class may be inherited by more than one class is known as hierarchical inheritance.
class A
{};
Class B:public A
{};
Class C:public A
{};
Class D:public A
{};
Where A is base class and B,C,D are derived classes.
A
B D
C
35. Hybrid inheritance
The combination of one or more types of inheritance is known as Hybrid inheritance.
Class A
{};
Class B:public A
{};
Class c
{};
Class D:public B, public C
{};
The above figure contains multilevel and multiple inheritance
A
C
D
B
36. Multipath Inheritance
When a class is derived from two or more classes that are derived from
same base class such type of inheritance is known as multipath
inheritance.
class A
{};
class B:public A
{};
class C:public A
{};
class D:public B, public C
{};
A
C
B
D
37. Defining derived classes
A derived class is defined by specifying its relationship with the base
class in addition to its own details. The general form of defining a
derived class is:
class derived class name: visibility mode base class name
{
members of derived class
}
The colon indicates that the derived class name is derived from the
base class name. The visibility mode is optional and if present may be
either private or public. The default visibility mode is private.
38. Continue..
class A: private B
{};
When a base class is privately inherited by a derived class, public
members of the base class become private members of the derived
class and therefore the public members of the base class can only be
accessed by the member functions of the derived class. They are
inaccessible to the objects of the derived class.
39. Continue..
Class A: public B
{};
When the base class is publicly inherited, public members of the base
class become public members of the derived class and therefore they
are accessible to the objects of the derived class
40. Protected
C++ provides a third visibility modifier, protected, which serve a limited purpose in
inheritance. A member declared as protected is accessible by the member
functions within its class and any class immediately derived from it. It cannot be
accessed by the functions outside these two classes.
Syntax: class class name
{
private: //optional
// visible to member functions within its class
protected: //visible to member functions of its own
// and derived class
public: // visible to all functions in the program
};