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

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -