考慮做:爲什麼使用聲明沒有公開成員指針
struct foo
{
void foobar(){}
};
struct bar : protected foo
{
using foo::foobar;
};
int main()
{
bar b;
b.foobar(); // Fine
&bar::foobar; // Not fine
}
我不知道是什麼理由使用聲明揭露成員出租,而不是一個指針。實際上,它似乎全部使用聲明來改變訪問級別,除了獲取一個暴露函數的地址外,其他所有內容都適用。
UPDATE:它類似於我的實際使用情況較好的一個例子:
#include "boost/bind.hpp"
struct foo
{
void foobar() {}
};
struct bar : protected foo
{
using foo::foobar;
bar() { boost::bind(&bar::foobar, this)(); } // Crashes VS2008, GCC 4.1.1 fails to compile as it tries to go through foo*
};
int main()
{
bar b;
}
然而,邁克Seymours'的解釋是現貨上,並解釋了爲什麼GCC失敗。謝謝!
確定嗎? http://ideone.com/HbRik –
@PaulManta - 可能只是VS2008然後,會做一些進一步的調查。 – Ylisar
也許你可以提到你在問題的主體中使用了哪個編譯器?除了提供信息外,它還能讓我刪除我的downvote。 – juanchopanza