this

this - this pointer void someFunction(Cat* cp) { // Do...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: this pointer void someFunction(Cat* cp) { // Do something with cp. } class Cat { public: ... void someCatFunction(); }; void Cat::someCatFunction() { someFunction(??); } Suppose you want to pass in “this Cat” to someFunction. this pointer void someFunction(Cat* cp) { // Do something with cp. } class Cat { public: ... void someCatFunction(); }; void Cat::someCatFunction() { someFunction(this); } Suppose you want to pass in “this Cat” to someFunction. this pointer • This means I could also have done: void Cat::meow() { cout << "meow" << endl; if ((*this).m_age < 100) (*this).m_age++; } • But we usually omit this when referring to its own members. ...
View Full Document

This note was uploaded on 07/06/2011 for the course CS 31 taught by Professor Melkanoff during the Spring '00 term at UCLA.

Ask a homework question - tutors are online