指定默认参数的朋友声明必须是一个定义 [英] Friend declaration specifying a default argument must be a definition

查看:863
本文介绍了指定默认参数的朋友声明必须是一个定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自更新到XCode 5.1以来,我的一个项目现在在标题中有错误,不会构建,我已经改变架构到32位,以前,但仍然是同样的问题。

Since updating to XCode 5.1 one of my projects now has that error in the title and will not build, I have changed architecture to 32-Bit as before, but still the same issue.

它引用的代码行是

friend float 
    DistBetweenModels (ShapeModel* pModel1, ShapeModel* pModel2,
                        enEvalType nEvalType = ET_EyeDist, enDistType nDistType = DT_Max); 

如果我删除了朋友并留下float项目构建,

If I remove the 'friend' and leave the 'float' the project builds but I am not confident it is doing what it should.

推荐答案


如果我删除了朋友 float项目构建,但我不确定它是做什么应该的。

If I remove the 'friend' and leave the 'float' the project builds but I am not confident it is doing what it should.

这绝对不是正确的事情。

That is definitely not the correct thing to do.

本< a>是相关问题。

This is the relevant issue.

具有默认参数的朋友声明也必须是一个定义。

A friend declaration with default arguments must also be a definition.

你有一些选择如何解决这个问题。您可以将此函数的定义移动到朋友声明中:

So you have some choices as to how to fix this. You can either move the definition of this function into the friend declaration:

friend float 
DistBetweenModels (ShapeModel* pModel1, ShapeModel* pModel2,
                    enEvalType nEvalType = ET_EyeDist, enDistType nDistType = DT_Max)
{
    // function definition goes here
}

或者,您可以删除friend声明中的默认参数:

Or you could remove the default arguments in the friend declaration:

friend float 
DistBetweenModels (ShapeModel* pModel1, ShapeModel* pModel2,
                    enEvalType nEvalType, enDistType nDistType);

但是你应该确保在这个函数的命名空间范围内有一个较早的非朋友声明包括默认参数。

But you should make sure that there's an earlier, non-friend declaration at namespace scope of this function that includes the default arguments.

我会选择第二个解决方案;定义类外的函数并移动默认参数。这是因为对于在线定义的朋友函数,有一些明确的名称查找。内联好友函数只能用于预期通过ADL调用的函数(例如运算符重载)。

I would choose the second solution; defining the function outside the class and moving the default arguments there. This is because there are some subtleties with name-lookup for friend functions which are defined inline. Inline friend functions should only be used for functions that are expected to be called via ADL (such as operator overloads).

这假设函数需要是一个朋友。如果没有,您可以删除此朋友声明。

This assumes that the function does need to be a friend. If not then you can just remove this friend declaration.

这篇关于指定默认参数的朋友声明必须是一个定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆