MX2- keyword 'friend'

About Monkey 2 Forums General Discussion MX2- keyword 'friend'

This topic contains 2 replies, has 2 voices, and was last updated by  degac 2 years, 7 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #3449

    degac
    Participant

    I’m looking at the TED2 source code and I find the ‘keyword’  FRIEND.

    For what is/should be used???

    Just pure curiosity!

    #3453

    impixi
    Participant

    Though recognized by the MX2 lexer, “Friend” is an unimplemented keyword. Mark has probably reserved it for possible future inclusion in MX2.

    Assuming “Friend” will allow functionality similar to the C++ equivalent, it can be useful.

    Wikipedia link:
    https://en.wikipedia.org/wiki/Friend_class

    Also read the first “answer” in this stackoverflow thread:

    http://stackoverflow.com/questions/17434/when-should-you-use-friend-in-c

    EDIT: The best example I’ve seen that makes use of “Friend” classes (in C++) is in the object pooling chapter of Game Programming Patterns by Robert Nystrom. BTW, I highly recommend that book.

    The same chapter he also demonstrates good use of Unions (something else not (yet?) in MX2), but I digress… 😉

    #3461

    degac
    Participant

    Thanks,

    So – if ever implemented & like the C language – is a way to allow another class to access the ‘private/protected’ part of another one: it’s a sort of ‘authorization’.

    Considering the stackoverflow’s example, If you write a ‘base’ class and don’t specify what are ‘your’ friends immediately, you need – in future – to change the base every time you would like to access the protected things.

    With this logic, make everything private, and add – then- only the sub-classes authorized.

    In a ‘public’ project (where different heads have different visions) this approach is very limiting.
    Honestly, I don’t like very much the ‘private’ thing at all (or the need to make a method Overridden in the main class!), this feature is just another complication in code design to me!

    Thanks anyway!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.