This shows you the differences between two versions of the page.
cns:labs:lab-10 [2021/01/11 16:58] mihai.dumitru2201 [C++ objects memory layout] |
cns:labs:lab-10 [2021/01/11 16:59] (current) mihai.dumitru2201 [C++ objects memory layout] |
||
---|---|---|---|
Line 327: | Line 327: | ||
}; | }; | ||
- | D objD; B1 * ptrB1; | + | int main() |
- | ptrB1 = &objD; | + | { |
- | ptrB1->z(); | + | D objD; B1 * ptrB1; |
+ | ptrB1 = &objD; | ||
+ | ptrB1->z(); | ||
+ | } | ||
</code> | </code> | ||
Line 349: | Line 352: | ||
We can also use the compiler to see the data layout. Copy the code above into | We can also use the compiler to see the data layout. Copy the code above into | ||
- | a file ''dummy.cpp'' and add a main function to make it a valid program: | + | a file ''dummy.cpp''. |
- | <code cpp> | + | |
- | int main() { return sizeof(D); } | + | |
- | </code> | + | |
Then run: | Then run: |