'class's friend function are incompatible?

IDE throws warning that the class's friend function are not compatible with the function's declaration outside of class. What is the cause for the warning?

namespace CommonUtility
{
    Interface::CellType Foo(int);
}

// when placed as friend of class Interface
class Interface
{
public:
    static enum class CellType
    {
        Group,
        NoSuchType
    };
    friend Interface::CellType CommonUtility::Foo(int); // IDE warning not compatible to the declaration 
}

// definition
Interface::CellType CommonUtility::Foo(int i)
{
  if (i == 1)
   return Interface::CellType::Group;
  else
   return Interface::CellType::NoSuchType;
}
c++


Solution 1:[1]

  1. For Interface::CellType Foo(int); the Interface::CellType is unknown at that point and should result in a compiler error.
  2. static enum class CellType would also result in a compiler error, because static is not correct here.

And finally:

The declaration of Interface::CellType CommonUtility::Foo(int); has to exists before friend Interface::CellType CommonUtility::Foo(int); can be used. But Interface::CellType Foo(int); can only be declared as soons as Interface::CellType is known. CellType is a nested type and cannot be forward decaled.

And these conditions conflict with each other.

You would need to move the whole enum class CellType {} outside of class Interface to get that working.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1