CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: friend function

  1. #1
    Join Date
    Sep 2003
    Location
    Jakarta
    Posts
    111

    friend function

    for what reason should I use friend function?
    isn't friend function break the encapsulation concept of class?
    Last edited by zacharya; October 15th, 2003 at 08:48 AM.

  2. #2
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470
    Answer to part 1: you should try to avoid using friends unless it is absolutely necessary. When is it necessary? Rarely. Probably the most common (and "safest") is if you make a contained class a friend of the containing class. At least, this is the situation in which I've mostly found myself using friends.

    Answer to part 2: Yes. It also increases coupling, so is doubly a bad thing
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured