🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3864

Re: Suggestion to the C++ standard

#3864
From: David Bradley
Date: Fri, 29 Mar 1996 17:07
67 lines
2642 bytes
jdmorris@ix.netcom.com (Jason D. Morris) wrote:

>#ifndef PROPERTY_H__
>#define PROPERTY_H__
>
>// The property class controls access to a captive variable.
>// It captures the get/set pattern.  This class first appeared
>// in the November/December 1995 Vol. 7 / No. 9 Issue of C++ Report
>// in the article Patterns in Practice: A property template for C++
>// by Colin Hastie.
>
>template < class T >
>class property
>{
>private:
>    T content;  // captive variable
>    
>    // non-implemented non-accessible assignment operator
>    void operator =( const property< T >& );
>
>public:
>    // ctors
>    property() {}
>    property< T >( const T& t )
>        : content( t )
>    {}
>
>    // accessors
>    T operator()() const   // get
>    { return content; }
>
>    void operator()( const T& t )  // set
>    { content = t; }
>};
>
>#endif
>
>
>To use this class you'd do something like this...
>
>class foo
>{
>public:
>    property< int > foo_number;
>};

On the surface this sounds good.  The obvious problem is the issue of
access.  You may want the a private set and public get.

Another problem is you are unable to perform any validation within the
set function.

Lastly the naming of the data member/accessors breaks most common
styles.  Usually the member functions are distingiushed in some manner
from the data members.

===============================================
DISCLAIMER: I may be a member of humanity,
but I'm not a spokesman for humanity.
	davidb@datalytics.com
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]
Technical Details
Message-ID: <315c0f6e.956220382@news.datalytics.com>
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
References: <4jatnm$s9b@post.tau.ac.il> <31599c95.4890732@nntp.ix.netcom.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
From: davidb@datalytics.com (David Bradley)
Newsgroups: comp.std.c++
Subject: Re: Suggestion to the C++ standard
Date: 29 Mar 1996 09:07:43 PST
Organization: Datalytics Inc.
Approved: austern@isolde.mti.sgi.com
Message-ID: <315c0f6e.956220382@news.datalytics.com>
References: <4jatnm$s9b@post.tau.ac.il> <31599c95.4890732@nntp.ix.netcom.com>
NNTP-Posting-Host: isolde.mti.sgi.com
X-Original-Date: Fri, 29 Mar 1996 16:34:55 GMT
X-Newsreader: Forte Agent .99d/32.182
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBVAwUBMVwY4Ey4NqrwXLNJAQGdJQIAtygERoHSMes/0QLdOJqEbi4YtF6sr+uy
 04i9oWKkpHKTCDhSUEdVGdfRSSKbWhIa7dzlG5NxB//b0BJfmRqQ1w==
 =zgef
Originator: austern@isolde.mti.sgi.com