这不编译,
#include <boost/intrusive_ptr.hpp>
class X
{
public:
void intrusive_ptr_add_ref(X* blah)
{
}
void intrusive_ptr_release(X * blah)
{
}
};
int main()
{
boost::intrusive_ptr<X> ex(new X);
}
但这确实:
#include <boost/intrusive_ptr.hpp>
class X
{
public:
friend void intrusive_ptr_add_ref(X* blah)
{
}
friend void intrusive_ptr_release(X * blah)
{
}
};
int main()
{
boost::intrusive_ptr<X> ex(new X);
}
还有这个 :
#include <boost/intrusive_ptr.hpp>
class X
{
public:
};
void intrusive_ptr_add_ref(X* blah)
{
}
void intrusive_ptr_release(X * blah)
{
}
int main()
{
boost::intrusive_ptr<X> ex(new X);
}
我想这与 SFINAE 有关(我还没有费心去理解)?朋友限定符是否将定义的函数作为自由函数放在封闭的命名空间中?
编辑
谁删除了他们的帖子,成员函数 non-friend asadd_ref
和(文档release
中没有提到这些特定的成员函数......)确实解决了这个问题。带有限定符的嵌套定义会发生什么?friend