#include< iostream>
using namespace std;
template< class t>
class X
{
private:
t x;
public:
template< class u>
friend u y::getx(X< u> );
void setx(t s)
{x=s;}
};
class y
{
public:
template< class t>
t getx(X< t> d)
{return d.x;}
};
int main()
{
X< int> x1;
x1.setx(7);
y y1;
cout<< y1.getx(x1);
return 0;
}
When compiling the above program, an error was detected that yis neither a function nor a member function, therefore it cannot be declared a friend. How to include getxas a friend in X?
source
share