Say i want a friend function to have access to two classes which are derived from the same base..I declare the friend function prototye in both classes, but where do i code the actual definition?? is the code below right?? (mixBreed() is the friend function)..
// Dog.h
#include "Animal.h"
#ifndef Dog_h
#define Dog_h
using namespace std;
class Dog{
protected:
int ID;
public:
int getID(){return ID;} //17. Inline methods..
void setID(int newID){ID=newID;}
};
class Retriever;
class Alsation: public Dog{
private:
int height, weight;
public:
Alsation(int aHeight, int aWeight);
Alsation(){};
friend void mixBreed(const Alsation &, const Retriever &); //Prototype
Alsation operator+ (Alsation x);
Alsation Alsation::operator= (const Alsation &y);
bool Alsation::operator == (Alsation x);
void display();
};
class Retriever: public Dog{
private:
int height, weight;
public:
Retriever(int aHeight, int aWeight);
friend void mixBreed(const Alsation &, const Retriever &); //Prototype
};
void mixBreed(const Alsation &x, const Retriever &y){
cout << x.height + y.height << endl;} //Friend function definition
#endif