Membrii De Tip Static Ai Cl

  • Uploaded by: Patrick Johnston
  • 0
  • 0
  • July 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Membrii De Tip Static Ai Cl as PDF for free.

More details

  • Words: 227
  • Pages: 1
Membrii de tip static ai claselor O variabila membru static exista inainte de a fi creat orice obiect din acea clasa. De aceea el poate fi utilizat direct in main(). Si deoarece exista inainte de crearea unui obiect, i se poate da oricand o valoare, dar nu in clasa in care este declarat, ci cand este definit. #include using namespace std; class Comun { static int static_a; //error: static int static_a = 2222; nu este permisa initializarea la declarare int b; public: void init(int i) {b = i; } void modify(int i) {static_a = i; }; void arata(); };

int Comun::static_a = 1111; //defineste static_a; ATENTIE!!!!! //se mai poate si: int Comun::static_a; //fara sa initializam variabila deci /* declararea lui static_a in afara cat si in interiorul clasei Comun este necesara deoarece declararea lui static_a in interiorul lui Comun nu determina alocarea de memorie */ void Comun::arata() { cout<<"static_a = "<<static_a<<" b = "<

Related Documents

Tip
April 2020 31
Static
October 2019 27
Static
November 2019 28
Cl
October 2019 68
Cl
June 2020 42

More Documents from ""