10
useVim
2y

WTH, TIL there's a "friend" keyword in C++

Comments
  • 10
    C++ is an endless source new things to learn.
  • 10
    @Lensflare It is the Underdark of languages. It devoured countless of unsuspecting adventurers that ventured too deep and never saw the sun again...
  • 5
    @Lensflare "a trove of very niche rarely used features which actually make sense at some point"
  • 11
    friend classes and functions can access a classes privates... Which leads to a plethora of 8 year old jokes.
  • 1
    if you have a set of classes that are operating tightly with each other, are within the same library, and within the same area of function, sometimes the use of friends can improve performance, because you can circumvent calling methods and access attributes directly and stuff like that. It can be quite useful in some very special cases.

    Most of the use i got out of it, is when splitting a class into multiple subclasses that went into different files, while still maintaining a policy on what's accessible and what not to the rest of the codebase.
  • 3
    “Your friends can touch your privates”
    “You’ve got a friend in you”

    As a grown man I still chuckle every time I use this keyword
  • 0
    @Datamind If it's inside of you, doesn't that make it a parasite or a germ or a virus? A friend should be outside of your body. :-D
  • 0
    You got a friend in C (++)
  • 0
    Friends with benefits
Add Comment