9

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.

The line of code it refers to is;

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

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

Volker
  • 4,640
  • 1
  • 23
  • 31
user3355723
  • 235
  • 2
  • 11
  • You might want to get rid of the "objective-c" tag on your question because it will attract the wrong kind of people…like me. :) (You need a C++ or Objective-C++ person.) – Phillip Mills Mar 20 '14 at 12:50
  • Oops sorry :D I just removed it now – user3355723 Mar 20 '14 at 12:51
  • 1
    Find the implementation of `DistBetweenModels` and see whether it accesses any private or protected members of the class that contains the `friend` declaration. If not, you can remove it entirely. – Henrik Mar 20 '14 at 15:30

1 Answers1

15

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.

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
}

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.

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.

bames53
  • 86,085
  • 15
  • 179
  • 244