C++ Class method not working as expected
C / C++ / MFC
1
Posts
1
Posters
4
Views
1
Watching
-
I have to make class Buffer with 3 private members: kapacitet - capcity of buffer, brojElemenata - number of elements in buffer, and bafer - buffer array in which elements are stored; public function push which stores element in bafer. Here is my code: #include using namespace std; class Buffer { private: int kapacitet; int brojElemenata; int *bafer = new int[kapacitet]; public: Buffer() { kapacitet = 0; brojElemenata = 0; } Buffer(int n) { kapacitet = n; brojElemenata = 0; } ~Buffer() { delete [] bafer; } void push(int el) { if(brojElemenata >= kapacitet) cout << "Bafer is full." <