※ 引述《tinlans.bbs@whshs.cs.nccu.edu.tw (汀)》之銘言:
: ※ 引述《txt.bbs@bbs.ntu.edu.tw (筆記本)》之銘言:
: > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: > 快 教大家一下 怎麼開不是 32 bits 的 pointer
: class member function pointer,
: 這是 C++ 特有的 function pointer,
: size 在大部分的 C++ 環境都是一般指標的兩倍,
: 這個 overhead 也算是 C++ 的常識之一,
: 不過很多教授不知道...
: #include <iostream>
: using namespace std;
: class X {
: void foo() { }
: };
: int main()
: {
: void (X::*ptr)(void);
: cout << sizeof(ptr) << endl;
: return 0;
: }
tinlan大大您好 感謝您為我們解惑
版上也常拜讀您的文章 受益不少^^
但是此例小弟實驗結果 怎麼都還是4 byte呢
編譯環境 VC6 console mode
哪裡有問題呢?編譯環境沒設定好嗎
#include <iostream>
using namespace std;
class X{
void foo(void){}
};
int main()
{
void (X::*ptr)(void);
cout<<sizeof(ptr)<<endl;
int* pt=new int(6); //一般pointer
cout<<sizeof(pt)<<endl;
return 0;
}
兩者皆輸出 4
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.162.102.125