Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Pointers to Members - Advanced Programming - Lecture Slides, Slides of Computer Science

These are the Lecture Slides of Advanced Programming which includes Class Data Members, Class Data Initializers, Class Objects, Class Instructor, Constructor Initializer, User Defined Types, Appropriate Constructors, Class Declaration, Name of Base Class etc. Key important points are: Pointers to Members, Member Function Invocation, Return Pointer, Direct Reference to Members, Before Configuration, Pointers to Data Members, Pointers to Member Functions, Class Student

Typology: Slides

2012/2013

Uploaded on 03/21/2013

dharmaraaj
dharmaraaj 🇮🇳

4.4

(65)

153 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Classes
this & pointers to members
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Pointers to Members - Advanced Programming - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Classes

this & pointers to members

Self-Reference -- this

  • A Pointer to the Object, which is Used in Member Function Invocation -- this
  • A Return Pointer to that Object
  • Direct Reference to Members of the Object in a Member Function is Possible
  • this is NOT Available to friend Functions

this -- Example 2

  • /* Use of "this" in a doubly linked list */ class student{ int ss; student *next; student *prev; public: void append(student *); };

this -- Example 2

  • void student::append(student *ip){ ip->next = next; ip->prev = this; next->prev = ip; next = ip; }
  • void my_function(student *new_student){ student *head; // ... head->append(new_student); }

this -- Example 2

Head

( this )

ss prev next

ss prev next

ss prev next

ss prev next ip

After configuration

*void student::append(student ip){ ip->next = next; ip->prev = this; next->prev = ip; next = ip;

Pointers to Members

  • Pointers to Data Members
  • Pointers to Member Functions

Pointers to Member Functions -- Example

  • class student{public: int ss, credits;student():ss(0), credits(0){} int return_ss(){return ss;}int return_credits(){return credits;} };
  • main(){// "pmf" is a pointer to a member function of "student" that returns int int (student::pmf)();pmf = student::return_ss; // "pmf" is pointing to "return_ss()" student s1;cout << (s1.pmf)() << endl; //"s1.return_ss()" is invoked "return_credits()"pmf = student::return_credits; // "pmf" is pointing to } cout << (s1.*pmf)() << endl; //"s1.return_credits()" is invoked