我很想知道初始化成員變量在內存中的位置?即,CSS,BSS,數據段,堆...成員變量駐留在哪個內存段中?
如果我的問題是愚蠢的不要罵我:) 例如
class A
{
A();
int m_iVar;
}
A::A(int i)
{
m_iVar = i;
}
A::A()
{
m_iVar = 99;
}
main()
{
A o; // => After compilation, the object o, in which segment does it reside? and especially where does "m_iVar" reside
A o1(5); // => After compilation here object o1, in which segment does it reside?and especially where does "m_iVar" reside?
A *pA = new A; // After compilation, here the memory pointed by pA, I guess it goes to heap, but the variable "m_iVar" where does it reside
}
無處。編譯器沒有任何理由爲此生成代碼。 –
相關:http://stackoverflow.com/q/18834568/951890 –
你爲什麼不看看自己? :)查看編譯器生成的彙編指令是一個有趣的練習,並且只要您有調試符號,就可以輕鬆查看所有內容的存儲位置。 –