O'Reilly logo
  • Jason Ford thinks this is interesting:

Listing 9.13. Using the friend Keyword to Allow an External Function DisplayAge() Access to Private Data Members


Cover of Sams Teach Yourself C++ in One Hour a Day, Seventh Edition


HELP PLEASE - DisplayAge in main() won't compile, even though I have void DisplayAge(const Human& Person) in public AND friend void DisplayAge(const Human& Person) in private. Should this be the other way around? Use "friend" in the public DisplayAge function???? This is not compiling in Visual Studio 2012, it gives the following error: error LNK2019: unresolved external symbol "void __cdecl DisplayAge(class Human const &)" (?DisplayAge@@YAXABVHuman@@@Z) referenced in function _main fatal error LNK1120: 1 unresolved externals