Thread: Member function from class as a friend in another class

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by std10093 View Post
    In general it is not good to have friend classes.
    On what grounds? It does not violate encapsulation. Use of "friend" can be justified, if you need to grant access to a class or function. Friend classes can be justified if they are meant to be coupled (any changes to one class implies changes to another class as well).

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Quote Originally Posted by whiteflags View Post
    On what grounds?
    I have in mind what grumpy said its 1st paragraph. I suppose that we should design our code, like if it was to be handled by 100 programmers, even though it may be just for fun. That way, when the time comes for big projects, you are going to be prepared
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by std10093 View Post
    I have in mind what grumpy said its 1st paragraph.
    Nowhere did I say that friend classes are bad (or not good) things. I said, in effect, that it is best to grant no more access to data within objects than needed. Friend declarations - be they of friend functions, friend classes, or friend member functions - provide a means for selectively grant access.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with namespace function declared as friend of class
    By Programmer_P in forum C++ Programming
    Replies: 7
    Last Post: 09-22-2012, 12:46 PM
  2. Replies: 4
    Last Post: 03-22-2012, 01:11 PM
  3. friend function template class declaration error
    By -EquinoX- in forum C++ Programming
    Replies: 2
    Last Post: 11-20-2009, 01:00 PM
  4. Replies: 8
    Last Post: 03-19-2008, 03:04 AM
  5. Replies: 5
    Last Post: 06-04-2002, 02:33 PM

Tags for this Thread