C
C# Learner
I'm a bit curious about how OOP works "under the hood".
Consider this (C++) class implementation:
<code>
class MyClass
{
int x;
void Method();
};
</code>
Now, as I understand it, this would actually be compiled down to
something like this:
<code>
struct MyClass
{
int x;
};
void MyClass_Method(MyClass *this);
</code>
....where the struct is a kind of C-type struct.
Okay... now to my question -- how does inheritance work at this level?
Does the compiler more or less "copy" the fields from the parent class
(struct) into the child class (struct)? Or does it do something else?
e.g.:
<code>
class Parent
{
public:
int parentField;
};
class Child : public Parent
{
public:
int childField;
};
</code>
Here, Child seems to have parentField and childField. What goes on
"under the hood" to achieve this?
Consider this (C++) class implementation:
<code>
class MyClass
{
int x;
void Method();
};
</code>
Now, as I understand it, this would actually be compiled down to
something like this:
<code>
struct MyClass
{
int x;
};
void MyClass_Method(MyClass *this);
</code>
....where the struct is a kind of C-type struct.
Okay... now to my question -- how does inheritance work at this level?
Does the compiler more or less "copy" the fields from the parent class
(struct) into the child class (struct)? Or does it do something else?
e.g.:
<code>
class Parent
{
public:
int parentField;
};
class Child : public Parent
{
public:
int childField;
};
</code>
Here, Child seems to have parentField and childField. What goes on
"under the hood" to achieve this?