Article View: alt.comp.lang.learn.c-c++
Article #372Re: Class and pointer problem
From: Terry Harris
Date: Wed, 30 Jun 1999 00:00
Date: Wed, 30 Jun 1999 00:00
32 lines
1812 bytes
1812 bytes
"Magnus Hult" <hult.holmstrom@swipnet.se> wrote:
>The only way I've been able to get through this problem is to do like this:
>
>class Object {
> public:
> int id;
> Object(int);
>};
>
>Object *ptr; // Here C++ knows what an Object is, and I haven't
>used ptr yet
>
>Object::Object(int idnum) {
> id = idnum;
> ptr = this;
>}
>
>which isn't a very smooth solution,
Someone else told you about forward declarations. IMO this is a
'smooth' - well better solution anyway, although you should inline
the constructor if you really want the same functionality as you had.
The public section of a class definition is your 'contract' with class
users (or clients), you shouldn't clutter it up with anything the
clients don't need to know - especially code. Kind of a philosphical
style thing.
Cheers Terry...
Technical Details
Message-ID:
<377971b4.8301783@news.dial.pipex.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<S3be3.496$nZ5.796@nntpserver.swip.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f8d38,c03b176bbf53f537 X-Google-Attributes: gidf8d38,public X-Google-Thread: 114592,c03b176bbf53f537 X-Google-Attributes: gid114592,public X-Google-Thread: 109fba,c03b176bbf53f537 X-Google-Attributes: gid109fba,public From: terry.harris@iname.com (Terry Harris) Subject: Re: Class and pointer problem Date: 1999/06/30 Message-ID: <377971b4.8301783@news.dial.pipex.com> X-Deja-AN: 495421880 Content-Transfer-Encoding: 7bit References: <S3be3.496$nZ5.796@nntpserver.swip.net> Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@uk.uu.net X-Trace: lure.pipex.net 930706262 14628 193.149.81.102 (30 Jun 1999 01:31:02 GMT) Organization: UUNET WorldCom server (post doesn't reflect views of UUNET WorldCom Mime-Version: 1.0 NNTP-Posting-Date: 30 Jun 1999 01:31:02 GMT Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cpp.language,comp.lang.c++