#include using namespace std; // we need this so that BuddyT "knows" that a PalT definition is coming. class PalT; class BuddyT { friend void TalkAboutBuddyT(BuddyT & buddy); friend class PalT; public: BuddyT()= default; // delay implimentation until after PalT is declared. void DoBuddysMatch(const PalT & pal); private: string name{"buddy"}; int contacts{0}; }; void TalkAboutBuddyT(BuddyT & buddy); class PalT { friend class BuddyT; public: PalT(BuddyT buddy): myBuddy{buddy} {}; void HelpBuddy(void) { ++myBuddy.contacts; } BuddyT & ShareBuddy(void) { return myBuddy; } void RatOutBuddy(void) const { cout << "In PalT My Buddy is: " << myBuddy.name << endl; cout << "\t contacts: " << myBuddy.contacts << endl; } private: BuddyT myBuddy; }; void BuddyT::DoBuddysMatch(const PalT & pal) { if (pal.myBuddy.contacts == contacts and pal.myBuddy.name == name) { cout << "Oh boy, this Pal's buddy matches me." << endl; } else { cout << "Sadness, their buddy is not the same as me" << endl; } } int main() { BuddyT buddy; PalT pal(buddy); buddy.DoBuddysMatch(pal); pal.HelpBuddy(); pal.RatOutBuddy(); TalkAboutBuddyT(pal.ShareBuddy()); pal.RatOutBuddy(); return 0; } void TalkAboutBuddyT(BuddyT & buddy) { cout << "In TalkAboutBuddyT My Buddy is: " << buddy.name << endl; cout << "\t contacts: " << buddy.contacts << endl; ++buddy.contacts; }