davin.50webs.com/research
Bringing to you notes for the ages
Safe properties in C++
Abstract
Since C++ properties such as char's, int's, float's, doubles and
pointers are left uninitialised by the C++ compiler, it makes sense to
prefer property types whose values are initialised to definite values.
If not, then the values of these properties will be undefined (i.e.
random values depending on the current values of the data at those
memory locations) if you attempt to use these values before they are
set. This article is an alternative to an earlier article .
1. Introduction
Here is a definition of the safe_int class that is intended
to replace int properties.
class safe_int
{
public :
int v ;
safe_int ()
{
v = 0;
}
safe_int (int v )
{
this ->v = v;
}
operator int () const
{
return this ->v;
}
};
To do an operation like ++ you need to use access the v property.
For example if you have the following definition:
safe_int x ;
The you need to write the following code to increment this value:
(x.v)++
Similarly to do an operation like x += y; you need to write
x.v += y; .
This page has the following hit count:
| Main Menu
| Research Projects
| Photo Album
| Curriculum Vitae
| The Greatest Artists
|
| Email Address
| Computer Games
| Web Design
| Java Training Wheels
| The Fly (A Story)
|
| Political Activism
| Scruff the Cat
| My Life Story
| Smoking Cessation
| Other Links
|
| Debugging Macros
| String Class I
| Linked List System I
| Java for C Programmers
| Naming Convention
|
| String Class II
| How I use m4
| Strings III
| Symmetrical I/O
| Linked Lists II
|
| Run-Time Type Info
| Virtual Methods
| An Array System
| Science & Religion
| Submodes
|
| Nested Packages
| Memory Leaks
| Garbage Collection
| Internet & Poverty
| What is Knowledge?
|
| Limits of Evolution
| Emacs Additions
| Function Plotter
| Romantic Love
| The Next Big Thing
|
| Science Fiction
| Faster Compilation
| Theory of Morality
| Elisp Scoping
| Elisp Advice
|
| S.O.G.M. Pattern
| Safe Properties
| School Bullying
| Charisma Control
| Life and Death
|
| Splitting Java
| Multiple Ctors
| Religious Beliefs
| Conversation 1
| Conversation 2
|
| J.T.W. Language
| Emacs Additions II
| Build Counter
| Relation Plotter
| Lisp++ Language
|
| Memory Leaks II
| Super Constructors
| CRUD Implementation
| Order a Website Form
| There Is An Afterlife
|
| More Occam's Razor
| C to Java Translator
| Theory of Morality II
Last modified: Sun Sep 25 16:12:03 NZDT 2016
Best viewed at 800x600 or above resolution.
© Copyright 1999-2016
Davin Pearson.
Please report any broken links to