Object Oriented Programming Features Part 3 | C ++ Tutorial | Mr. Kishore

Naresh i Technologies
7 Jan 201730:35

Summary

TLDRIn this 'Nourish 80' episode, Kishore dives into object-oriented programming, focusing on the distinctions between C structures and C++ classes. He elucidates that C++ classes support both variables and functions, unlike C structures, and highlights the default privacy of class members versus the public nature of C structure members. Kishore also explains concepts like encapsulation, data hiding, and inheritance, which are pivotal to object-oriented programming. The video is a comprehensive guide for beginners looking to understand the fundamentals of classes in C++.

Takeaways

  • πŸ“˜ The class in C++ is an extension of the C structure, allowing both variables and member functions within its definition.
  • πŸ”‘ A major difference between C structures and C++ classes is that by default, C structure members are public, while C++ class members are private.
  • 🏭 C++ classes support the concept of inheritance, unlike C structures, which cannot be used as a base for deriving other structures.
  • πŸ‘₯ C++ classes are used for constructing complex programs due to their support for inheritance, while structures are typically used for simpler programs.
  • πŸ“¦ Classes in C++ act as a blueprint for creating objects, serving as a logical copy from which multiple physical instances (objects) are made.
  • πŸ”’ Classes provide the concept of encapsulation, bundling data and member functions into a single unit and controlling access to the data through member functions.
  • πŸ™ˆ Data hiding is achieved in classes through private access specifiers, ensuring that class data is not directly accessible from outside the class, promoting security.
  • πŸ“ Member functions can be defined both inside and outside of the class definition, with different implications for inline functions and scope resolution.
  • πŸ‘€ Access to private class members must be done through public member functions, illustrating the principle of data hiding and encapsulation.
  • πŸ› οΈ The class syntax includes the class keyword, class name, access specifiers, data members, member functions, and ends with a semicolon.
  • πŸ“š Understanding the differences between C structures and C++ classes is crucial for utilizing object-oriented programming features effectively in C++.

Q & A

  • What is the main difference between C structures and C++ classes?

    -The main difference is that C structures only allow variables inside them, while C++ classes allow both variables and member functions, which are functions defined within the class.

  • What are the three types of access specifiers provided by C++ classes?

    -The three types of access specifiers are private, public, and protected. These specifiers determine the visibility and accessibility of the class members.

  • Why are member functions in a class necessary when the data members are private?

    -Member functions are necessary to access and manipulate private data members, as direct access from outside the class is restricted. This is part of the encapsulation concept in object-oriented programming.

  • What is the purpose of encapsulation in object-oriented programming?

    -Encapsulation is the mechanism of binding data (variables) and member functions together into a single unit, which is the class. It is used to hide the internal state of an object and require all interaction to be performed through an object's methods.

  • What is data hiding in the context of classes?

    -Data hiding is the concept where the internal data (data members) of a class are kept private and are not directly accessible from outside the class, ensuring that the data can only be manipulated through member functions.

  • Why is it important to have at least one public member function in a class?

    -At least one public member function is important because it allows for interaction with the class's private data members. Without a public interface, the class would be inaccessible and thus, not useful.

  • What is the default access level for class members in C++?

    -By default, class members in C++ are private, meaning they are not accessible from outside the class unless specifically made public or protected through access specifiers.

  • Can structures in C++ be used for inheritance?

    -No, structures in C++ do not participate in inheritance. Only classes can be used as base classes to derive other classes.

  • What is the difference between defining a member function inside and outside the class?

    -Defining a member function inside the class makes it an inline function, which can be expanded at the point of use by the compiler. Defining it outside the class requires the use of the class name and scope operator, and it does not have the inline property.

  • How is an object of a class declared in C++?

    -An object of a class is declared by specifying the class name followed by the object name. For example, if the class name is 'Student', an object can be declared as 'Student s;'.

  • What is the role of the scope operator (::) when defining a member function outside the class?

    -The scope operator (::) is used to specify that the function being defined is a member of the class. It distinguishes the member function from global functions with the same name.

Outlines

00:00

πŸ“š Introduction to Object-Oriented Programming

The script begins with an introduction to Object-Oriented Programming (OOP) by Kishore, focusing on the continuation of OOP concepts from a previous session. It explains the basic difference between C structures and C++ classes, highlighting that C++ allows both variables and functions within a class, unlike C structures which only allow variables. The explanation includes the default access levels of structure members in C and C++, emphasizing that C++ class members are private by default, unlike C structures which are public. The paragraph sets the stage for a deeper dive into OOP features.

05:03

πŸ—οΈ Differences Between C Structures and C++ Classes

This paragraph delves into the distinctions between C structures and C++ classes. It clarifies that while both are user-defined and complex data types, C++ classes differ by being involved in inheritance, allowing for the derivation of one class from another, which is not possible with structures. The paragraph also touches on the use case scenarios, suggesting that structures are typically used for simpler programs, whereas classes, due to their inheritance capabilities, are better suited for building complex applications. The summary of similarities and differences is aimed at helping understand the appropriate use of each.

10:04

πŸ” Class Concepts: Encapsulation and Data Hiding

The third paragraph discusses the concept of encapsulation in classes, which is the bundling of data and functions into a single unit. It also explains data hiding, a feature that keeps the class's data private, accessible only through member functions, thus securing the data from external access. The paragraph emphasizes that classes provide a blueprint for creating objects, serving as a logical plan that does not occupy memory, unlike objects which are physical instances and do require memory allocation.

15:05

πŸ“ Class Syntax and Access Specifiers

This section provides an overview of the syntax for declaring a class in C++. It explains the use of access specifiers such as private, public, and protected, which determine how class members are accessed. The paragraph clarifies that by default, class members are private, meaning they are not accessible outside the class unless through a public or protected interface. It also touches on the syntax for declaring objects and the importance of ending class declarations with a semicolon.

20:06

🚫 Private Members and Data Access in Classes

The focus of this paragraph is on the private nature of class members and how they are accessed within the class. It explains that private data members cannot be directly accessed or initialized outside the class or by objects, but must be manipulated through member functions. The paragraph also discusses the error that occurs when attempting to access private members directly and the necessity of having at least one public member function to make the class useful.

25:07

πŸ”„ Member Function Definitions Inside and Outside the Class

This paragraph explains the two ways of defining member functions in C++ classes: inside the class declaration, which makes the function an inline function, and outside the class declaration, which requires the use of the class name and scope operator. It provides an example of a class with private data members and a public member function for accessing and modifying the data. The summary highlights the importance of proper member function definition placement and the mechanics of memory allocation when objects are created.

30:07

πŸ”š Conclusion and Future Topics

The final paragraph wraps up the current discussion on classes and member functions, indicating that future sessions will continue with the remaining topics in object-oriented programming. It provides a brief mention of the next topics, such as friend functions and pointers, setting the stage for further learning and exploration in the realm of C++ and OOP.

Mindmap

Keywords

πŸ’‘Object-Oriented Programming (OOP)

Object-Oriented Programming is a programming paradigm that uses 'objects' to design applications and software. These objects are instances of 'classes', which can contain data, in the form of fields (often known as attributes or properties), and code, in the form of procedures (often known as methods). In the video, OOP is the central theme, with a focus on features like classes and objects, which are fundamental to OOP.

πŸ’‘Class

A class is a blueprint or template for creating objects. It defines the properties (data members) and methods (member functions) that the objects will have. The video script discusses the concept of a class in the context of C++, highlighting the differences between C structures and C++ classes, and emphasizing that classes in C++ can contain both variables and functions, unlike C structures which traditionally only contain variables.

πŸ’‘Object

An object is an instance of a class. It is a concrete entity that is created based on the class blueprint. The script mentions objects in the context of encapsulation, where a class binds data and functions into a single unit, and objects are the physical representations of these class definitions in a program.

πŸ’‘Encapsulation

Encapsulation is one of the fundamental concepts of OOP. It refers to the bundling of data with the methods that operate on that data, or the restricting of direct access to some of an object's components. The video script explains that classes in C++ provide encapsulation, allowing for the binding of data and member functions into a single unit, which helps in organizing code and maintaining data privacy.

πŸ’‘Data Members

Data members are variables declared inside a class, representing the state of an object. The script explains that data members are part of the class and contribute to the object's state once an object is instantiated. They are often used in conjunction with member functions to manipulate the object's state.

πŸ’‘Member Functions

Member functions are functions declared inside a class and are used to define the behavior of objects created from that class. The script discusses member functions in the context of C++ classes, noting that they are part of the class's definition and can access the class's data members, even if they are declared as private.

πŸ’‘Access Specifiers

Access specifiers in C++ are keywords that determine the accessibility of class members. The script mentions three types: private, public, and protected. These specifiers play a crucial role in defining the visibility and accessibility of data members and member functions within a class and from outside the class.

πŸ’‘Private Members

Private members are class members that are only accessible within the class itself. The script explains that by default, all class members in C++ are private, meaning they cannot be accessed directly from outside the class. This is a key aspect of data hiding and encapsulation, ensuring that the internal state of an object is protected from unauthorized access.

πŸ’‘Public Members

Public members are class members that can be accessed from outside the class. The script contrasts private members with public members, noting that public data members and member functions can be accessed directly using an object's instance, which is essential for interacting with objects in a program.

πŸ’‘Inheritance

Inheritance is a feature of OOP that allows a new class to be based on an existing class. The script briefly mentions inheritance as a feature that differentiates classes from structures in C++, stating that classes can participate in inheritance, meaning you can derive one class from another, which is not possible with structures.

πŸ’‘Data Hiding

Data hiding is the practice of restricting access to an object's data members to protect the object's integrity. The script discusses data hiding in the context of private access specifiers in C++ classes, which ensure that the class's data is not directly accessible from outside the class, promoting safer and more controlled access through member functions.

Highlights

Introduction to Object-Oriented Programming (OOP) features in C++

Difference between C structures and C++ classes, including access to member functions

C++ classes allow both variables and functions unlike C structures

C structures are public by default, while C++ class members can be private, public, or protected

Explanation of the two major differences between C structures and C++ structures

Introduction to the concept of classes in C++ and their differences from structures

Classes in C++ are user-defined and complex data types

Classes are collections of variables (data members) and functions (member functions)

Classes provide encapsulation, binding data and functions into a single unit

Classes offer data hiding through private member declarations

Classes serve as blueprints for creating objects, occupying no memory unlike objects

Syntax of a class in C++, including access specifiers and member declarations

Default access levels for class members in C++, with private being the default

Inheritance is a key feature of C++ classes, distinguishing them from structures

Classes are suitable for building complex programs due to inheritance capabilities

Member function definitions can be inside or outside the class in C++

Accessing private class members through public member functions

Declaration of class objects and memory allocation for each object

Conclusion and continuation of the remaining OOP topics in future sessions

Transcripts

play00:02

[Music]

play00:08

hi welcome to nourish 80 this is Kishore

play00:12

and today we are going to continue the

play00:15

object-oriented programming features in

play00:19

last session we have discussed some of

play00:21

the object-oriented features such as

play00:23

class and object today we are going to

play00:27

continue the remaining features of

play00:30

object-oriented programming now first of

play00:33

all I am giving brief examples of class

play00:36

and object first what is a class what is

play00:40

an object okay now say this class is the

play00:44

extension of C structure and the major

play00:47

difference between C structure and C++

play00:50

classes C structure allows C structure

play00:54

arrows only the variables inside the

play00:57

structure which are called structure

play01:00

members but C++ class hellos both the

play01:04

variables under member functions means

play01:07

nothing but functions which are called

play01:09

member functions that is why here I am

play01:12

giving the differences between C

play01:14

structure C++ structure and this class

play01:18

understructure simplest way structure

play01:20

first I am going to give structured C

play01:23

structure differences and C++ structure

play01:26

okay that is why first it is the C

play01:29

structure and it is the C++ structured

play01:32

now first thing is C structure is

play01:37

collection of variables and C++

play01:41

structure is collection of variables and

play01:46

functions next C structure is by default

play01:53

public that means structure members are

play01:57

by default public X here C++ structure

play02:02

members are private or public are

play02:07

protected okay we can declare the C++

play02:12

structure members in three ways one is

play02:15

private mode another one is public mode

play02:18

and another one is protected number now

play02:20

these

play02:21

are the two major differences in between

play02:24

the C structure and C++ structure and

play02:27

working style everything is similar to C

play02:30

that means both working style and

play02:33

everything is same to same the only

play02:35

differences first one is collection of

play02:37

variables means a see structures doesn't

play02:41

allows functions inside the structure

play02:43

and C++ allows both to the variables and

play02:47

functions inside the structure and here

play02:50

see structure members are by default

play02:53

public that means anybody can that means

play02:56

anybody can means here in the total

play02:59

program we can access the structure

play03:01

members from anywhere but here they are

play03:04

private public protected these are the

play03:07

two major differences between the C

play03:10

structure and C++ structure now I said

play03:14

C++ classes okay we are declaring the

play03:18

class are we are getting the class from

play03:21

C structure that is why now I am giving

play03:24

what is the difference between structure

play03:27

and class okay these are these are the

play03:30

differences between C structure and C++

play03:33

structure now I am going to view the

play03:35

differences between structure and class

play03:38

okay now first one C++ structure and it

play03:46

is the class now the first difference is

play03:50

of course generally everybody knows it

play03:54

is a user-defined and here also it is

play03:59

user-defined

play04:01

okay now I am giving similarities and

play04:03

differences both that is why here C++

play04:06

structure is called user defined class

play04:09

also called

play04:10

user-defined okay next it is a complex

play04:15

data type here also same thing complex

play04:20

data type next here

play04:24

the point is collection of variables and

play04:30

functions

play04:33

simplify structure is the collection of

play04:35

variables and functions as usual class

play04:38

also collection of variables and

play04:43

functions next now fourth one members or

play04:51

private or public are predicted

play04:58

now simple structure members are private

play05:02

public or product and the same thing is

play05:05

happening here numbers are private are

play05:11

public are protected now these are the

play05:17

common things they are looking to be say

play05:19

okay now the four properties are looking

play05:22

to be same now the difference is what ok

play05:27

here the first major difference is here

play05:31

by default members are public by default

play05:35

members or public that means when there

play05:42

is no visibility label or access

play05:44

specifier is not mentioned ok when no

play05:47

visibility label or x4 is not mentioned

play05:50

automatically all the members will

play05:52

become public members that means anybody

play05:56

can access from anywhere and here by

play06:00

default class members are private it is

play06:03

a major difference by default class

play06:07

members are private that means only the

play06:10

authorized it means only the member

play06:13

functions of same class are accessible

play06:16

outside members are not accessible it is

play06:19

the first major difference in between

play06:22

the C++ structure and class next here

play06:27

not inherited it is the major another

play06:31

major difference okay structures are not

play06:35

participated in inheritance means from

play06:38

one structure we are not able to derive

play06:40

another structure but classes are

play06:44

inherited okay from one class we can

play06:48

declare another class or from one class

play06:51

we can derive another class that is why

play06:53

classes are participating in inheritance

play06:57

next you would to build simple data

play07:03

types our programs generally structures

play07:09

we are using for constructing a simple

play07:12

programs that means not the chrome

play07:14

complex programs okay for example bank

play07:17

examples railway reservations like that

play07:19

okay in big projects we are not able to

play07:22

use the structure concept only they are

play07:24

limited for simple programs under here

play07:28

they are easier for complex programs

play07:31

easy to build complex programs that is

play07:39

why by using the class concept because

play07:42

of inheritance is alone okay

play07:44

due to that future using C++ classes we

play07:48

can construct a big projects it is the

play07:52

major advantage of class these are the

play07:54

similarities and differences between the

play07:57

C++ structure and the class okay now it

play08:02

is nothing but a similarities and

play08:04

differences of class next now how to

play08:08

declare the class and what are the

play08:10

definition of class okay now I am giving

play08:13

class a string it is a user-defined data

play08:18

type okay class is called it is a

play08:22

user-defined data type because of we are

play08:24

constructing the class by using the

play08:26

primitive and a derived data types as

play08:28

per the user requirement that is why

play08:31

class is called it is a user-defined

play08:34

datatype next it is a complex data type

play08:39

class is a complex because of different

play08:42

types of data types are available at one

play08:44

place that is why it is a complex data

play08:47

type next it is a it is collection of

play08:51

members it is collection of members that

play08:56

means class

play08:57

contains different types of numbers what

play08:59

they are means one data members nothing

play09:05

but variables mixed second one is number

play09:10

functions

play09:12

nothing but functions okay let us say

play09:17

here the point is classic members that

play09:20

means what class contains both the data

play09:23

members and member functions which are

play09:26

collectively known as members that means

play09:29

here data members means nothing but a

play09:31

variables that are declared inside the

play09:34

class are called data members and the

play09:37

functions that are declared inside a

play09:40

class are called member functions and

play09:42

collectively both are called members

play09:46

okay

play09:47

next class is a container that means

play09:52

which contains the members because of

play09:54

one container container means what which

play09:56

contains something here it contains

play09:59

something what data members and member

play10:01

functions that is why class is a

play10:03

container next class provides the

play10:08

concept of encapsulation means what when

play10:14

class is user to class contains what

play10:16

both the data members and member

play10:19

functions that means class allows to

play10:22

bind class allows to hide different

play10:25

types of variables and functions into a

play10:29

single unit called class okay now class

play10:33

allows to place different types of

play10:36

variables and member functions are

play10:38

functions into a single unit called

play10:41

class and this mechanism is called

play10:43

encapsulation okay it is nothing but

play10:47

encapsulation next class provides the

play10:51

concept of data hiding with private

play10:58

declaration already we have discussed

play11:00

class members are either private or

play11:03

public are protected okay here the main

play11:08

point is when the members are private

play11:11

only the member functions of that class

play11:15

are able to access the data that means

play11:18

outers are not allowed at any cost

play11:21

except the pointers friend functions

play11:25

except the pointers and friend functions

play11:28

which are discussed in later sessions

play11:30

okay here that is why an important point

play11:33

of classes when the class data is

play11:36

private it is not visible outside the

play11:40

class that is called data hiding that is

play11:44

why the key factor of data hiding is

play11:48

achieved with the private declaration

play11:51

that LS well allowed by the class the

play11:54

swea class provides the concept of data

play11:57

hiding with the private declaration next

play12:00

class easy blueprint means original copy

play12:07

to construct the objects that's why here

play12:13

on important thing is class is a

play12:15

blueprint class is a blueprint here

play12:18

blueprint means original copy to

play12:21

construct objects that means to

play12:24

construct the objects first of all we

play12:26

should have to define the class because

play12:30

of class is the nothing but a plan okay

play12:35

that is that is it is a plan get here

play12:41

watch it it is a plan before

play12:44

constructing the objects they say to

play12:50

construct the objects first of all we

play12:53

have to make a plan for example to

play12:56

construct a building we should have to

play12:58

go for ok plan that means we are going

play13:02

to meet the planner which is also called

play13:06

architect ok first of all we are going

play13:08

for civil engineer who is also called

play13:10

architect now he is going to draw a plan

play13:13

on the paper

play13:15

based on that plan the Builder is going

play13:18

to construct the building that is why

play13:22

here one most important point is

play13:25

class is a plan class is a plan means

play13:29

paper plan which is used to construct

play13:33

the objects in my example paper plan is

play13:37

the class and the real building is the

play13:39

objects that is why class is a logical

play13:44

copy to construct the physical copies

play13:48

which are called objects that is why

play13:51

class is a okay here it is the most

play13:55

important point class is a logical copy

play14:01

to create objects because of here class

play14:08

never occupies any memory okay here

play14:12

because of class never occupies any

play14:15

memory and objects always occupies the

play14:18

memory that is why objects are called

play14:21

physical representation of classes now

play14:25

these are the important features of

play14:27

class that means what is a class under

play14:29

what class provides that is why class

play14:31

means it is a user-defined data type

play14:35

okay here class is a user-defined data

play14:39

type X it is a complex data type it is

play14:43

collection of members what are the

play14:45

numbers available means data members

play14:47

member functions and what is called

play14:50

later member means the variables that

play14:52

are declared inside the class are called

play14:54

data members and the functions are

play14:57

called member functions that is why

play14:59

class is nothing but a container which

play15:02

contains the both data members and

play15:04

member functions and class provides the

play15:07

concept of encapsulation and capsulation

play15:09

refers to be-what binding of data and

play15:12

member functions together into a single

play15:15

unit called

play15:15

class next class provides the concept of

play15:18

data hiding that means what outers are

play15:21

not tell or means the private data is

play15:23

fully secured and it should be accessed

play15:26

with only the member functions of that

play15:28

class it is not visible outside the

play15:30

class it is called data hiding feature

play15:33

and here class is a blueprint just

play15:37

before you have finished

play15:38

to construct the objects we have to draw

play15:40

the plan and that plan is nothing but

play15:42

class and the plan is called blueprint

play15:45

blueprint means to original copy okay

play15:48

next it is a plan before constructing

play15:50

the objects that is why class is a

play15:52

logical way because class never takes

play15:55

any memory only the object takes the

play15:58

memory that is why class is a logical

play16:01

copy and objects are the physical

play16:03

instances of the class okay next what is

play16:07

the syntax of a class okay now I am

play16:11

going to give syntax of the class

play16:13

generally the class is started like this

play16:16

class and here class name and class name

play16:23

is optional when the object is declared

play16:27

immediately after the class here class

play16:30

is a keyword the denotes we are going to

play16:34

start a class here and here we have to

play16:37

enter the class name and class name is

play16:39

optional when the objects are declared

play16:42

immediately next here visibility label

play16:46

our axis specifiers next data members

play16:54

nothing but variables and member

play16:59

functions member functions nothing but

play17:04

functions next it is the class closing

play17:10

and here one important thing is here we

play17:14

can declare the class variables which

play17:16

are called objects and here important

play17:21

thing is when the class variables or

play17:23

objects are declared okay and the class

play17:26

variables or objects are declared

play17:29

immediately after the class means here

play17:32

then class name is not required it is

play17:34

purely optional but whenever the class

play17:37

variables are not declared here we have

play17:40

to declare some other places of the

play17:42

program then the class name is mandatory

play17:45

and every class should have to end with

play17:49

the semicolon it is another important

play17:51

thing

play17:52

now it is nothing but the syntax of a

play17:54

class thus every class should have to

play17:57

start with class keyword and every class

play18:00

is having a particular name it is

play18:01

optional when the variables are declared

play18:03

immediately next access specifier now

play18:07

what is called access specifier the name

play18:10

is very clear it specifies how they are

play18:14

going to be accessed okay

play18:16

it specifies how they are going to be

play18:18

accessed in our programs under class

play18:22

provides three types of access

play18:25

specifiers one is private another one is

play18:30

public and another one protected okay

play18:36

insular C++ we are going to use three

play18:39

types of access specifiers or visibility

play18:43

labels now we are going to use private

play18:46

public protected now what is happening

play18:49

when private and public unprotected I am

play18:52

going to explain what is happening when

play18:54

private is is serious suppose I am going

play18:57

to use private declaration now whenever

play19:00

the data members or number functions are

play19:03

private okay they are directly not

play19:06

accessible with the objects for example

play19:09

I am going to declare int a now see this

play19:14

is called data number and here I have

play19:19

not used it any access specifier means

play19:22

either private or public or protector

play19:24

now automaticall pilar assumes it is a

play19:28

private because of by default class

play19:32

members are private okay remember this

play19:34

by default all the class members are

play19:38

private when class members are private

play19:41

okay especially data members are private

play19:43

they should be accessible with the

play19:45

member function for example now I am

play19:49

going to write here why you get just you

play19:52

zoom get is one of the member function

play19:55

and here inside this a equal to hundred

play19:58

later c OT no function flows and it is

play20:04

100% allowed

play20:06

because of here the rule is private data

play20:08

should be accessed with member functions

play20:11

of same class and here a is declared

play20:14

inside of the class get also declared

play20:16

inside the class that is why they are

play20:18

called numbers that is why private deter

play20:20

should be accessed with another member

play20:22

functional ok the so it is except there

play20:25

is no problem and one more most

play20:27

important point in say + place it is not

play20:30

allowed int equal to for example hundred

play20:34

now this kind of declaration use error

play20:37

number function not declared here member

play20:40

function not initialized here error it

play20:42

is going to show that is why members

play20:45

data member should be initialized or

play20:48

user or access it with a member function

play20:51

only director initializations are not

play20:55

allowed it is one of the most important

play20:58

role next

play21:00

now what happens watch it it is provided

play21:02

and it is also private number function

play21:05

because of no access specifier mentioned

play21:08

now a Terry I want to access this member

play21:11

function suppose just as you it is the

play21:15

main function here I have declared one

play21:18

object for example it is the object now

play21:21

object two dot a equal 100 now it gives

play21:26

error an objective dot get it also gives

play21:31

error okay both in both situations we

play21:35

are getting error because of now a is a

play21:38

private member get also private number

play21:41

where members are private they are

play21:44

directly not accessible with the objects

play21:47

okay it is a most important role in

play21:50

class okay when the data members are

play21:53

member functions are private they should

play21:56

okay they are not available to the

play21:59

object directly using dot membership

play22:02

operator here I have user dot what is

play22:05

called membership operator dot is called

play22:08

what number ship operator and when the

play22:12

members are private we are not able to

play22:14

access with the object name directly

play22:17

that is why you

play22:19

is better to use one public member

play22:22

function now public now what happened a

play22:26

will become private member but gate will

play22:29

become public member and public number

play22:31

directly accessible with the object that

play22:34

is why it is not allowed but this one is

play22:37

allowed object to not gate okay that is

play22:41

why to access the members okay

play22:44

that is why what I want to say is when

play22:46

the all when all the class members are

play22:48

private it is useless okay

play22:52

why because to access the up class

play22:54

numbers we should have to declare the

play22:56

object and where the object is generally

play22:59

declared and where the members are

play23:00

called from main function actually main

play23:03

function is outside the class but in CPP

play23:06

the main rule is what members are not

play23:09

visible private members are not visible

play23:11

outside the class but what happened now

play23:15

the private member is a private member

play23:17

get also private number that is why it

play23:20

is not visible which is called data

play23:23

hiding that is why when they are not

play23:26

visible how can we access that is why

play23:28

this class is useless class that is why

play23:31

just to declare at least one class as a

play23:35

public number otherwise use the friend

play23:37

functions otherwise use the points okay

play23:40

but later we are going to discuss

play23:42

foreign function because of right now we

play23:44

are for sure that is why I am NOT going

play23:46

to discuss about fine function and

play23:48

pointers and now thus why you have to

play23:51

maintain at least one public number

play23:53

function inside the public member

play23:55

function we can call the private members

play23:58

that is why now I am going to give

play24:00

picture full picture clarity watch this

play24:03

I am going to give the public private or

play24:05

protected because right now I am NOT

play24:07

able to give the protected members

play24:09

because of the protected members are

play24:11

used only in inheritance concept when

play24:14

inheritance is started there I am going

play24:16

to explain what is protected member now

play24:18

I am going to give private and public

play24:20

declarations and how the private members

play24:23

are accessed inside the class now just

play24:26

example see this class for example

play24:30

student

play24:31

now private and here every access

play24:37

specifier should have to end with :

play24:39

symbol it is the most important role

play24:41

next int ID next character name next

play24:47

float fee now these three members are

play24:51

called data members next I am going to

play24:55

start like this for example I want to

play24:58

make public then directly public and it

play25:02

is another axis specifier now why did I

play25:06

get here I am going to write like this

play25:09

see out enter ID comma name comma feed

play25:16

now CN is required okay

play25:20

see in ID name see here Co t is what see

play25:28

n is odd because of we have not

play25:30

discussed enough that's why I am giving

play25:31

small karate see this here Co T is

play25:34

nothing but printf in C language and

play25:37

scene is nothing but scanf in c language

play25:39

that is why one is for output purpose

play25:42

one is for input it is going to printer

play25:44

the matter it is going to read the

play25:46

values okay now it is the program later

play25:49

I want to put into the data void see out

play25:52

ID equal to ID and and L means nothing

play25:59

but a /nc language generally in c

play26:02

language we are using / installation

play26:04

means what next line the so here and L

play26:06

is the manipulator which is used for

play26:09

next line next co t name no name is

play26:14

printed and l and c out fee fee also

play26:23

print no function closed class closed it

play26:27

is the example and here private and

play26:31

public they are called access specifiers

play26:38

okay here private and public are called

play26:41

taxes specific ID name fee they are

play26:44

nothing but data members and gate is the

play26:46

member function that is why class is

play26:50

collection of data members and member

play26:53

functions with the access specifiers and

play26:56

now watch it what happens it is the

play26:58

class declaration and definitions and

play27:01

here in C++ we can define the member

play27:04

functions in two ways one is inside the

play27:06

class by using this method now your

play27:09

compiler understands it is a inline

play27:11

function what is a inline function in

play27:13

later session we are going to start okay

play27:15

after that we are going to discuss that

play27:17

because of it is a different concept

play27:19

inline function is what and now here the

play27:22

definition is completed within the class

play27:24

that is why it is called okay member

play27:26

function definition inside the class and

play27:28

we can define the member function

play27:30

outside of the class also now I am going

play27:33

to give how outside of the class it is

play27:36

defined simple logic just in case of

play27:39

this one see this suppose public wide

play27:43

get no class close okay now the class is

play27:47

closed

play27:48

now here the role is whenever the

play27:51

definition is outside we should have to

play27:53

start the class name s T u : : gate and

play27:58

here it is not a inline function

play28:01

remember this when the definition is

play28:03

completed inside the class it will

play28:06

become inline function but it is Right

play28:08

notes but whenever the definition is

play28:10

completed outside of the class you

play28:12

should have to use classname and scope

play28:15

operator it is a most important role

play28:18

when the definition is completed outside

play28:21

of the class you should have to start

play28:23

with the class name first let us cope

play28:25

operator later member function now in

play28:29

two ways we can define the member

play28:30

function one is inside one is outside it

play28:33

is the example for outside another one

play28:36

inside next now I want to access this

play28:39

one I want to access the function and

play28:41

gate is the public member or private

play28:43

member except it is exactly public

play28:46

member that is why here I am going to

play28:48

declare the object void

play28:51

mein now how to declare the object

play28:54

class-name first space object that's all

play28:59

now it is the syntax to declare the

play29:01

object that is why first class name

play29:04

object here our class name is what

play29:06

student that is why in class name st you

play29:09

later object name is user-defined

play29:12

suppose yes now this is the object okay

play29:16

when object is created what happens the

play29:19

memory is allocated here ID is their ID

play29:22

which type integer

play29:23

the SOI two bytes name here name we have

play29:27

to store several characters now 20

play29:30

characters float fee four bits because

play29:32

of float the so four plus twenty plus

play29:36

two total 26 bytes memory allocated in

play29:40

stack it is the ID it is the name and it

play29:47

is the fee it takes two bites only 20

play29:51

bytes it for total 26 bytes and gate

play29:55

function is there now Kanaka I am going

play29:59

to call like this s dot get it is called

play30:03

what calling plus at our program plus

play30:07

when this function is called get is

play30:09

going to call this one and it is going

play30:11

to read and print the data it is how to

play30:14

access the class members it is how to

play30:18

access the class members okay in later

play30:21

session we are going to continue the

play30:22

remaining topic okay thank you for

play30:25

watching

play30:27

you

play30:28

[Music]

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
OOP FeaturesC++ ClassesC StructuresProgramming TutorialEncapsulationData HidingInheritanceMember FunctionsClass BlueprintObject Creation