oop - How are objects of subclasses allocated in C++? -
i have confusion concept of inheritance in c++, suppose have class named computer , publicly inherit class named laptop computer class. when create object of class laptop in main function happens in memory? please explain.
i'm assuming laptop inherits computer, , explaining happens in general; implementation details of c++ (for optimization reasons) may differ general explanation.
logically, laptop class definition has pointer computer class definition. instance of laptop class has pointer laptop class definition (in c++, reference array of function pointers class methods).
when laptop object receives message, first looks in own method table corresponding function. if not there, follows inheritance pointer , looks in method table computer class.
now, in c++, of happens in compilation phase, in particular believe method table flattened , calls can statically bound shortcut.
Comments
Post a Comment