namespace cpp {}

C++ lernen, kennen, anwenden

Benutzer-Werkzeuge

Webseiten-Werkzeuge


kennen:beispiel:static

Beispiel static

static.cpp
#include <algorithm>
#include <iostream>
 
static char const* const dateiname = __FILE__;
static char const* const erstellungsdatum = __DATE__;
 
char phlegmatisch(char x)
{
  static char last = '?';
  swap(x, last);
  return x;
}
 
struct Zaehler
{
  static int erhoehen() { return anzahl++; }
private:  
  static int anzahl;
};
 
int Zaehler::anzahl = 0;
 
int main()
{
  std::cout << dateiname << '\n';
  const char* p = erstellungsdatum; 
  while (*p) 
  {
    std::cout << Zaehler::erhoehen() << '\t' << phlegmatisch(*p++) << '\n';
  } 
  std::cout << Zaehler::erhoehen() << '\t' << phlegmatisch(' ') << '\n';
}
kennen/beispiel/static.txt · Zuletzt geändert: 2020-07-27 10:33 von 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki