Re: Code guidelines, state of C++ compilers used, and general C++comments


Subject: Re: Code guidelines, state of C++ compilers used, and general C++comments
From: Leonard Rosenthol (leonardr@lazerware.com)
Date: Tue May 09 2000 - 07:48:32 CDT


At 8:13 AM +0100 5/9/00, Mike Nordell wrote:
>Since you mention "numerous examples", would you care to share at least
>two of these "perfectly acceptable and correct" eamples with us?

        Sure...

        In a GUI framework, you might have a base class of something
like CControl which would have the member variable of the OS's
"control handle", while all the specific subclass would reference it.
It wouldn't make any sense for each subclass to have their own "copy"
of that same member variable since all subclasses need it.

        Same is true in a set of stream classes where you might have
common stream attributes (length, position, etc.) in the base rather
the copied to each subclass.

>Just to give a glimpse of the maintenance nightmare we're facing, I found
>out that baseclass (protected) member variables got initialized/replaced
>by subclasses (in AbiWord).

        Initialization should take place during construction by
calling the base classes constructor:

CDerived::CDerived( int inValue )
        :CBase( inValue )
{
}

>There's also no way to know what class' member variables you're poking
>around with when you see e.g.
> m_pBase = new Derived;
>This implies that it's "your" member, but with protected member variables
>it might as well be a baseclass waaay up in the hierarchy. This is not
>only a matter of evil (tm), it's dangerous.
>
        So what's your suggestion? Make them all private, and create
inline accessor functions?

LDR

-- 
----------------------------------------------------------------------------
                   You've got a SmartFriend in Pennsylvania
----------------------------------------------------------------------------
Leonard Rosenthol      			Internet:       leonardr@lazerware.com
					America Online: MACgician
Web Site: <http://www.lazerware.com/>
FTP Site: <ftp://ftp.lazerware.com/>
PGP Fingerprint: C76E 0497 C459 182D 0C6B  AB6B CA10 B4DF 8067 5E65



This archive was generated by hypermail 2b25 : Tue May 09 2000 - 07:53:59 CDT