|
Home - Computerkurs Demos Editpointstatic Folderwatcher Gipsydrive Licenses Shrinkseries V4 More... All Asm Bas C C++ C# Couch CSS HTML Java JS Lisp OPAL PHP Perl PS Py SQL Win |
|
Downtown Programmer's Corner - Demos
DRAFT - code samples not yet checked
C++ includes C and adds new features to it. The new features are most notably classes, which make object oriented programming possible.
.
.
.
A pointer is a variable, that holds not the value itself, but the memory address, where the value is stored. The pointer has a type which determines, how many bytes the value does occupy at it's memory location.
There are two operators * and & involved, the both come in two distinct usages, which we try to tell apart below. Furthermore we discuss three special cases: pointers of type void, pointers to functions, pointers to pointers.
This is the most common use, it defines a pointer to a memory address which stores values of a specific type.
int * pInt = new int(5); // on heap
int * pInt = new int[5]; // on heap
int[] intArray = ... ; // on stack (CHECK)
Solves a pointer into it's referring object type and the concrete object respectively. [Löst einen Pointer auf in den dahinterstehenden Objekttyp bzw. das konkrete Objekt.]
int *p = new int(5); // pointer as usual
dowhat1(*pInt); // dereference p from pointer to value
.
int a = 5;
int p = &a; // p now contains the address of a
With references, a caller can pass a parameter to be changed by a function. If one return value is not enough, but we want two or more, we can to pass a parameter as a reference or as a pointer.
///void dowhat1(const int &a);
///void dowhat2(cont int *p);
void dowhat1(int &a); // declaration, note the &
void dowhat2(int *p); // declaration
int a = 5; // declare plus initialaize a value
dowhat1(a); // pass value, taken as reference
dowhat2(&a); // pass the pointer
We neet them if we want deal with a pointer before we know it's final type.
char* pChar = NULL;
int* pInt = NULL;
void* pVoid = NULL;
getMem(pVoid);
int t = getType(..);
int s = getSize(..);
int s2 = sizeof(..);
if (t == 0)
pChar = (char*) pVoid;
It's a delegate mechanism ...
It's a typedef on function pointers ... (very difficult syntax)
// supplement sample code ...
[It's not soo difficult ... we just need a telling example ...]
// supplement sample code ...
.
.
About the latest C++ Standard: Heise Open News www.heise.de/.. C++ 11 einstimmig als Standard angenommen ..html , pointing to Herb Sutter's herbsutter.com/.. we-have-an-international-standard-c0x-is-unanimously-approved and Bjarne Stroustrup's www2.research.att.com/~bs/C%2B%2B0xFAQ.html .
.
Imprint : www.trilo.de/imprint.html