Docsity

Member Functions-Object Oriented Programming-Lecture Slides, Slides of Object Oriented Programming

Partial preview of the text

Download Member Functions-Object Oriented Programming-Lecture Slides and more Slides Object Oriented Programming in PDF only on Docsity!

Object Oriented Programming

(OOP)

Lecture No. 8

Review

►

Class^ 

Concept  Definition

►

Data members ►

Member Functions ►

Access specifier

Member Functions (contd.)

►

Define member function inside the classdefinition

OR

►

Define member function outside the classdefinition^ 

But they must be declared inside class definition

Function Inside Class Body

class

ClassName

… public:ReturnType

FunctionName

Example

class

Student{

int

rollNo;

public:

void

setRollNo(int

aRollNo){

rollNo

aRollNo;

Function Outside Class Body

class

ClassName

{

… public:ReturnType

FunctionName

();

};ReturnType

ClassName

::

FunctionName

()

{

… }

Scope resolution

Inline Functions

►

Instead of calling an inline function compilerreplaces the code at the function call point ►

Keyword ‘inline’ is used to request compilerto make a function inline ►

It is a request and not a command

Example

inline

int

Area(int

len,

int

hi)

return

len

hi;

} int

main()

cout

Area(10,20);

Example

class

Student{

int

rollNo;

public:

void

setRollNo(int

aRollNo){

… rollNo

aRollNo;

Example

class

Student{

… public:inline

void

setRollNo(int

aRollNo);

}; void

Student::setRollNo(int

aRollNo){

… rollNo

=

aRollNo;

}

Example

class

Student{

… public:inline

void

setRollNo(int

aRollNo);

};inline

void

Student::setRollNo(int

aRollNo){

… rollNo

=

aRollNo;

}

Constructor

Constructor (contd.)

►

Constructor is a special function havingsame name as the class name ►

Constructor does not have return type ►

Constructors are commonly public members

Example

class

Student{

public:

Student(){

rollNo