Re: [問題] C++ 繼承 object model layout 問題
小弟從一本教科書"Inside C++ object model" 裡面提到compiler會mangle class的
member name
===================================書本內容==================================
In general, member names are made unique by concatenating the name of the member with that of the
class. For example, given the declaration
class Bar { public: int ival; ... };
ival becomes something like
// a possible member name-mangling
ival__3Bar
Why does the compiler do that? Consider this derivation:
class Foo : public Bar { public: int ival; ... };
Remember that the internal representation of a Foo object is the concatenation of its base and derived class
members:
// Pseudo C++ Code
// internal representation of Foo
class Foo { public:
int ival__3Bar;
int ival__3Foo;
...
};
============================================================================
這樣了話Hourlyworker internally tranform to
class Employee{
public:
print_3Employee()
{//do Employee method}
print_3Hourlyworker()
{//do Hourworker method}
};
當 Empoylee *ePtr=(Hourlyworker) &h; compiler則讓ePtr access 到
print_3Hourlyworker
不曉得小弟這樣理解object model對不對?
※ 編輯: gecer (111.255.9.13), 10/23/2017 22:52:02
※ 編輯: gecer (111.255.9.13), 10/23/2017 23:02:14
※ 編輯: gecer (111.255.9.13), 10/23/2017 23:02:36
※ 編輯: gecer (111.255.25.161), 10/24/2017 21:11:42
※ 編輯: gecer (111.255.25.161), 10/24/2017 21:13:46
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章