JiiPee <
n...@notvalid.com> wrote in news:MVfNx.1028$JB7...@fx42.am4:
> On 25/09/2015 16:27, Stefan Ram wrote:
>> JiiPee <
n...@notvalid.com> writes:
>>> Now this would do the job, but its a bit difficult way to do a simple
>>> single variable thing.
>> I'd do it this way too. It is not difficult.
>>
>
> ok, good to know people agree with it. So I can start using it then...
>
> I just felt the class for one variable only is a bit too "heavy", but
> thats the way to do it.
There are many useful classes with no data members at all in C++.
The general idea is that a single class should have a single
"responsibility". Managing the null-or-not-null data pointer seems a
pretty clear responsibility.
> Maybe the language can someday have a security key for this. It might
be
> a good new feature for C++ :)
Your probably mean the standard library, not the C++ core language.
Anyway, it is not so simple because it is not straightforward what should
happen if the pointer is not in the expected state in either of the
get/set part. In my own code I would probably put asserts there, instead
of just ignoring any inconsistencies (as your design appears to
prescribe).
Cheers
Paavo