When I try to implement friend function inside the class as shown below, I get an error, and I don't know why... It only happens when a non-argumental friend function is declared inside the class. The error is
display() is not defined in this scope
Code:
#include<iostream>
using namespace std;
class test{
private:
int x = 5;
public:
friend void display(){
test obj;
cout << obj.x << endl;
}
};
int main(){
display();
return 0;
}
Output should be simply: 5
But I get this error:
display is not defined()