M
Size: a a a
M
A
std::vector <std::vector<Section>>
) хранит информацию о типе и номере элемента в другом векторе. Я хотел бы от этого избавиться. Решил сделать вектор поля через родительский класс для трех векторов, так не придется обновлять номера на элементы.R
A
m
M
M
A
R
M
#include <iostream>
#include <vector>
#include "Section.h"
void print(const std::vector<ISection *> &test);
int main() {
std::vector<ISection *> test;
test.push_back(new FoodSection);
test.push_back(new CellSection);
test.push_back(new FoodSection);
std::cout << test[0]->getItem("") << std::endl;
print(test);
std::cout << std::endl;
std::cout << "Change third element to EmptySection" << std::endl;
test[2] = new EmptySection;
print(test);
}
void print(const std::vector<ISection *> &test) {
for (int i = 0; i < 3; i++) {
switch (test[i]->getType()) {
case food: {
std::cout << "[f]";
break;
}
case cell: {
std::cout << "[c]";
break;
}
case empty:
std::cout<< "[ ]";
break;
}
}
}
M
m
M
A
#include <iostream>
#include <vector>
#include "Section.h"
void print(const std::vector<ISection *> &test);
int main() {
std::vector<ISection *> test;
test.push_back(new FoodSection);
test.push_back(new CellSection);
test.push_back(new FoodSection);
std::cout << test[0]->getItem("") << std::endl;
print(test);
std::cout << std::endl;
std::cout << "Change third element to EmptySection" << std::endl;
test[2] = new EmptySection;
print(test);
}
void print(const std::vector<ISection *> &test) {
for (int i = 0; i < 3; i++) {
switch (test[i]->getType()) {
case food: {
std::cout << "[f]";
break;
}
case cell: {
std::cout << "[c]";
break;
}
case empty:
std::cout<< "[ ]";
break;
}
}
}
m
m
R
R
m