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

Main topics in this course are object-orientation, objects and classes, overloading, inheritance, polymorphism, generic programming, exception handling, introduction to design patterns. This lecture includes: Member, Function, Orient, Program, Object, Concept, Definition, Data, Member, Access

Typology: Slides

2011/2012

Uploaded on 08/08/2012

anchita
anchita 🇮🇳

4.4

(7)

113 documents

1 / 38

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Object Oriented Programming
(OOP)
Lecture No. 8
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26

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