Created
May 3, 2026 09:08
-
-
Save thinkphp/6768d04e7597286209d99e7e2ceae8f9 to your computer and use it in GitHub Desktop.
Exemplu utilizare static
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| class Contor { | |
| private: | |
| static int numarObiecte; | |
| public: | |
| Contor() { | |
| numarObiecte++; | |
| } | |
| static int getNumarObiecte() { | |
| return numarObiecte; | |
| } | |
| }; | |
| int Contor::numarObiecte = 0; | |
| int main(int argc, char const *argv[]) | |
| { | |
| Contor a, b, c; | |
| cout<<"Numar de obiecte: "<<Contor::getNumarObiecte()<<endl; | |
| //class::metoda | |
| //class::variabila_statica | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment