Startseite   |  Site map   |  A-Z artikel   |  Artikel einreichen   |   Kontakt   |  
  


informatik artikel (Interpretation und charakterisierung)

Klassen-templates


1. Java
2. Viren



. = parametrisierte Klassen, Klassen-Schablonen, generische Klassen
. wichtige Anwendung: Container-Klassen (z.B. BIDS von Borland)
. Beispiel:

Deklaration


template
class STACK

{
ElTyp *top;

ElTyp *bottom;
ElTyp *current;

public:
STACK (int gr=100);

~STACK();
void push(ElTyp e);

ElTyp pop();
int empty();

int full();

};

Implementierung der Element-Funktionen als Funktions-Templates


template

STACK ::STACK (int gr)

{

bottom = current = new ElTyp [gr];
top=bottom+gr;

}

template

STACK ::~STACK ()

{

delete [] bottom;

}

template
STACK ::void push (ElTyp e)

{
if (current!=top) *current++=e;

}

template

STACK ::ElTyp pop ()

{

if (current>bottom) current--;
return *current;

}

template

STACK ::int empty ()

{

return current==bottom;

}

template
STACK ::int full ()

{
return current==top;

}

main()


....
STACK iStack(10);

STACK fStack;
typedef STACK szSTACK;

szSTACK sSTACK;

...

iStack.push(17);
sStack.push(\"Karli\");

....
. bei Klassen-Templates können auch \"normale\" Parameter (nicht class) als Template-Parameter angegeben werden. Beispiel: Default-Stackgroesse

template
class STACK

{
ElTyp *top;

...
public

STACK (int gr=grdef);

...

};

main()


....
STACK

....
. Hinweis: Klasse zuerst mit konkretem Typ entwickeln und testen, erst danach parametrisieren! 4

 
 



Datenschutz
Top Themen / Analyse
indicator Controller- und Bus-Standards
indicator Mode 13h-
indicator Zuverlässigkeit
indicator Programmaufbau
indicator Alles über Programmiersprachen
indicator World Wide Web:
indicator Herstellerspezifische und offene Netze-
indicator Diascanner -
indicator Der IP-Header
indicator Inkonsistenz durch parallelen Zugriff auf Dateien




Datenschutz
Zum selben thema
icon Netzwerk
icon Software
icon Entwicklung
icon Windows
icon Programm
icon Unix
icon Games
icon Sicherheit
icon Disk
icon Technologie
icon Bildung
icon Mp3
icon Cd
icon Suche
icon Grafik
icon Zahlung
icon Html
icon Internet
icon Hardware
icon Cpu
icon Firewall
icon Speicher
icon Mail
icon Banking
icon Video
icon Hacker
icon Design
icon Sprache
icon Dvd
icon Drucker
icon Elektronisches
icon Geschichte
icon Fehler
icon Website
icon Linux
icon Computer
A-Z informatik artikel:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z #

Copyright © 2008 - : ARTIKEL32 | Alle rechte vorbehalten.
Vervielfältigung im Ganzen oder teilweise das Material auf dieser Website gegen das Urheberrecht und wird bestraft, nach dem Gesetz.
dsolution