fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4.  
  5. class PUNKT{
  6. public:
  7. PUNKT(int px=0, int py=0): x(px),y(py) {++zaehl;}
  8. PUNKT(const PUNKT& other): x(other.x),y(other.y) {++zaehl;}
  9. ~PUNKT() {--zaehl;}
  10. static void ausgabe();
  11. private:
  12. int x,y;
  13. static int zaehl; // Anzahl der Elemente
  14. };
  15.  
  16. int PUNKT::zaehl=0;
  17.  
  18. void PUNKT::ausgabe() {
  19. std::cout << zaehl << '\n';
  20. }
  21.  
  22. int main(int count, char **args) {
  23.  
  24. std::vector<PUNKT> test;
  25. test.push_back(PUNKT(2,3));
  26. test.push_back(PUNKT(2,3));
  27. test.push_back(PUNKT(2,3));
  28. PUNKT::ausgabe();
  29. test.clear();
  30. PUNKT::ausgabe();
  31. return 0;
  32. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
3
0