Docsity

Data Members - Object Oriented Programming - Lecture Slides, Slides of Object Oriented Programming

Partial preview of the text

Download Data Members - 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 class definition OR
  • Define member function outside the class definition - 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 operator

Inline Functions

  • Instead of calling an inline function compiler replaces the code at the function call point
  • Keyword ‘inline’ is used to request compiler to 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; }