如何排序类和友元函数的定义和声明?
我有一个函数是类的友元。因此该函数可以访问所有类成员。 但是,我对定义的顺序感到困惑。
如果函数位于类之前,那么它如何才能获取类成员呢?如果类位于函数之前,则它无法知道该函数。
如何解决这种交叉引用冲突?
所以我的代码
class BP_Interface
{
friend void CommonUtility::HandleToFrame(Handle&);
private:
Handle frame_in_model;
}
// followed by definition
namespace CommonUtility
{
void HandleToFrame(Handle& eR)
{
BP_Interface().frame_in_model = eR;
return;
}
}
Visual Studio IDE 显示错误,并表示无法访问 frame_in_model
。
I have a function that is friend of a class. Therefore the function can access all class member.
However, I am confused with the order of definition.
If the function comes before the class then how do could it even get the class member? if the class come before the function, then it cannot know the function.
How to solve such cross reference conflict?
So I have code
class BP_Interface
{
friend void CommonUtility::HandleToFrame(Handle&);
private:
Handle frame_in_model;
}
// followed by definition
namespace CommonUtility
{
void HandleToFrame(Handle& eR)
{
BP_Interface().frame_in_model = eR;
return;
}
}
visual studio IDE shows error, and says frame_in_model
cannot be accessed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在定义
BP_Interface
之前声明CommonUtility::HandleToGraph
并在稍后定义它。Declare
CommonUtility::HandleToGraph
before the definition ofBP_Interface
and define it later.