This is very simliar to this question, however, the function I am trying to make a friend returns an C enumerator. I cannot figure out the correct syntax:
#include <iostream>
extern "C" {
enum X {ONE};
int foo();
X bar();
}
namespace a {
class A {
public:
A(int a): a(a) {}
private:
friend int ::foo();
friend X ::bar(); // Doesn't work
int a;
};
}
extern "C" {
int foo() {
a::A a(1);
std::cout << a.a << std::endl;
return ONE;
}
X bar() {
a::A a(2);
std::cout << a.a << std::endl;
return ONE;
}
}
int main()
{
foo(); // outputs: 1
bar(); // doesn't compile
}
The friend X ::bar();
doesn't work. What is the correct syntax for that.
main.cpp:20:18: error: 'enum X' is not a class or a namespace
friend X ::bar();
^
main.cpp:20:18: error: ISO C++ forbids declaration of 'bar' with no type [-fpermissive]
main.cpp: In function 'X bar()':
main.cpp:22:7: error: 'int a::A::a' is private
int a;
^
main.cpp:35:18: error: within this context
std::cout << a.a << std::endl;
Try adding parenthesis to resolve parsing ambiguity
friend X (::bar)();