All pastes #1894011 Raw Edit

Klassenvariable

public cpp v1 · immutable
#1894011 ·published 2010-07-03 18:52 UTC
rendered paste body
#include <iostream>using namespace std;class Person{  public:    Person(string s)    :name (s)    {      cout << "Anzahl Personen: " << ++anzahl << endl;    }    ~Person()    {      cout << "Anzahl Personee: " << --anzahl << endl;    }    void hallo() const    {      cout << "Hallo, hier ist " << name << endl;    }    static int anzahl;    string name;};  int Person::anzahl = 0;  int main(){  Person foo("foo"),	 bar("bar");  cout << Person::anzahl << endl;  foo.hallo();  bar.hallo();}/* Ausgabe    Anzahl Personen: 1    Anzahl Personen: 2    2    Anzahl Personen: 1    Anzahl Personen: 0*/