Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //49_this
- #include <iostream>
- using namespace std;
- #include "Hannah.h"
- int main()
- {
- Hannah ho (23);//first we must create an object
- ho.printCrap();
- }
- //-------------------------------------------------
- #ifndef HANNAH_H
- #define HANNAH_H
- class Hannah
- {
- public:
- Hannah(int);//if we sent it 20, it say's h is equal to 20
- void printCrap ();
- private:
- int h;
- };
- #endif // HANNAH_H
- //--------------------------------------------------
- #include <iostream>
- using namespace std;
- #include "Hannah.h"
- Hannah::Hannah(int num)//if we send 23
- :h (num)// it takes 23 from main and set it equal to h
- {
- }
- void Hannah::printCrap (){
- cout<<"h= "<<h<<endl;//c++ assumes that you working with current object
- cout<<"this->"<<this->h<<endl;//explicitly tells that you working with this current object
- /*the ad of ho get the object and the
- object have a variable h and h is equal to 23*/
- //keyword this identify a special kind of pointer
- //this stores the address of current object that you working with
- // the address of ho use that object & the object has a variable h
- cout<<"(*this).h= "<<(*this).h <<endl; //dereferencing pointer, it's taking a memory location of
- // of the current object and calling a variables value (.h)
- //we using memory location
- }
Advertisement
Add Comment
Please, Sign In to add comment