How to make a member function of one class , the friend function of another class:
class car
{
private:
int speed;
char color[20];
public:
void input()
{
cin >> color >> speed;
}
void display(car c)// Member function of Class car, which i want to make friend function for Class Scooter
{
cout << c.color << endl << c.speed;
}
};
class scooter
{
public:
int input_i()
{
cin >> color >> speed;
}
friend void car:isplay(scooter); // I am trying to make the member function display() of Class car , friend function for Class scooter.
};
void display(scooter s)
{
cout << s.color << s.speed;// compiler error color and speed undeclared.
}
// I want to make color and speed visible in Scooter class my making display function , friend function of class scooter.
void main()
{
car c1;
scooter s1;
c1.input();
s1.input_i();
c1.display(c1);
s1.display(s1);
}
[In the above program i want to make the member function display() of class Car , the friend function for class Scooter, so that class scooter can access private data members(speed and color) of class Car.]
But i think there's a mistake in above coding , so please help me how i could do this, as compiler error: nonexistent function 'car:isplay' specified as friend
THANKS.....




isplay(scooter); // I am trying to make the member function display() of Class car , friend function for Class scooter.
Reply With Quote