Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c++ Subject: Re: Method that only one other class type may access Date: Tue, 04 Oct 2011 15:01:28 +1300 Lines: 37 Message-ID: <9ev7noFdlfU1@mid.individual.net> References: <9eufl3F5kfU7@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net 39+EYXrAgWCSUz0goVCCHA6J+vExh90I9kZcgXzlEvoGrn6MuJ Cancel-Lock: sha1:hoaE0xSMGsa3Emec8B4LeOplq7I= User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:10654 On 10/ 4/11 09:49 AM, Jorgen Grahn wrote: > On Mon, 2011-10-03, Ian Collins wrote: >> On 10/ 2/11 09:32 AM, Christopher wrote: >>> I know I need some sort of friend, but I don't want to friend the >>> entire class. >>> >>> I've got a TcpConnection class and it has a state member. >>> I've got a TcpListener class that accepts connections and creates a >>> TcpConnectionClass. >>> >>> The TcpListener class needs to be able to change the state member of >>> the TcpConnection class, but I don't want anyone else to be able to. >>> How do I go about that? >> >> If a design doesn't fit the problem, the design is flawed. It looks to >> me like you are over engineering what is a very simple (and common) >> task. Don't fret though, I see this all the time! Socket related >> activities simply don't fit well within an OO approach. > > It is not clear to me what you mean with that last sentence, but I was > going to say something similar: Trying to use things like connection and listener classes! > I see no great benefits of wrapping the BSD socket API in lots of stuff. > If you wrap them a bit to get: > > - file descriptors which aren't convertible to and from ints > - RAII > > then the API is pretty usable as it is. Bonus: anyone who knows the > API doesn't have to relearn another one. Agreed. -- Ian Collins