Answer the question
In order to leave comments, you need to log in
Empty C++ array, how to solve?
I wrote a program to learn OOP.
There is a field 5 by 5, at the beginning there is an installation of all objects on the field.
Question: why is the array empty?
#include <iostream>
class Poligon {
private: int G[5][5] = { 0 };
public: Poligon() {
}
void PoligonClear() {
//..обнулить G
for (int i = 0; i != 5; i++) {
for (int d = 0; d != 5; d++) {
Poligon::G[i][d] = 0;
}
}
};
void PrintPoligon() {
for (int i = 0; i != 5; i++) {
printf("%d | ", i + 1);
for (int d = 0; d != 5; d++) {
printf("%d ", G[i][d]);
}
printf("\n");
}
}
void Postavit(int i, int j, int x) {
G[i][j] = x;
printf("i: %d, j: %d, x: %d\n", i, j, x);
//PrintPoligon();
}
void GetInfo() {
PrintPoligon();
}
};
class Cat {
public: int Age = 1;
void Setage(int v) {
Age = v;
};
int Getage(void) {
return Age;
};
void Gulat(Poligon X, int i, int j) {
X.Postavit(i, j, Age);
}
};
class Dog {
public: int DogAge = 1;
void Setage(int v) {
DogAge = v;
};
int Getage(void) {
return DogAge;
};
void Gulat(Poligon X, int i, int j) {
X.Postavit(i, j, DogAge);
};
};
int main() {
Poligon W;
Cat Barsik;
Barsik.Setage(2);
Barsik.Gulat(W, 1, 2);
Dog Tusik;
Barsik.Setage(3);
Tusik.Gulat(W, 1, 3);
W.GetInfo();
return 0;
}
Answer the question
In order to leave comments, you need to log in
Because you don't have Setage calls, and in Gulat() you get Postavit(i, j, 0)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question