I was reading an old C++ book to do some retro coding, C++ for C Programmers by Sharam Hekmatpour, I remember reading it when I was way younger and I liked it.
In the friend
functions chapter he shows having two classes with friend functions:
class RealSet;
class IntSet {
public:
void ToRealSet(RealSet*);
friend void RealSet::ToIntSet(IntSet*);
};
class RealSet {
public:
void ToIntSet(IntSet*);
friend void IntSet::ToRealSet(RealSet*);
};
I know this won't compile because while we had defined RealSet
as a forward declaration, we don't have a definition to RealSet::ToIntSet
and that will make the compiler fail.
Yes, I know I could set the whole class as a friend class and that will solve the problem:
class RealSet;
class IntSet {
public:
ToRealSet(RealSet*);
friend class RealSet;
};
class RealSet {
public:
ToIntSet(IntSet*);
friend class IntSet;
};
My question is simple: Was this ever possible or is it a typical book mistake?