c++ - Why `this` can't access the derived class members from base class methods when called for derived class object -


this pointer has type of classname in non-const member functions.

 class base  {    public:      void get()      {        //this->put(); why can't call derived class method eventhough                         **this** pointing derived class object.      }  };   class derived: public base  {    public:    void put()    {     // somthing.    }  };   int main()  {   derived d;   //d.get();   d.put();   return 0;  } 

if print value of this pointer in both functions same, indicating called derived class object. , this pointers type derived * here.

also understand if have pointer object when you're calling method of you're pointing offset method present in whole object layout starting address present in pointer object.

but why can't offset derived class method when have start address of (derived)object in base class method.

i unbale why can't because of above understanding. missing basic here.

me: when compiler compiles base::get function, cannot see derived::put function.

you : isn't derived::put in same file? why can't compiler see that?

me: if there derived1::putttttt defined 4 years later deriving base in file?

you: mm, maybe understand.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -