Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

10. Statische Klassenelemente > Statische Methoden

Statische Methoden

Kommen wir noch einmal zurück auf die Auto-Klasse. Auch dort deklarieren wir das statische Feld nun als private. Allerdings möchte man auf das Feld anzahl wahrscheinlich schon von außerhalb der Klasse zugreifen können. Also bietet es sich an, dafür eine Eigenschaft Anzahl einzurichten. Allerdings sollte der Wert dieser Eigenschaft – bzw. des dahinter stehenden Felds anzahl – von außen nicht verändert werden, sodass man allein einen get-Accessor implementieren wird.

Headerdatei Auto.h:

ref class Auto
{
private:
   static int anzahl;
   int geschw_max;
   int geschwindigkeit;
public:
   Auto(void);
   Auto(int hoechstgeschw, int geschw);
   property static int Anzahl
   {
      int get();
   }
   property int Geschwindigkeit
   {
      int get();
      void set(int geschw);
   }
   ...
};

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial