考虑做:为什么使用声明没有公开成员指针
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