реализация класса стены и его дочерних классов, а также самого стека.
здесь я добавляю классы в стек и с помощью функции isBuildingCorrectly проверяю, смогу ли я вставить следующий объект, но при доступе поля объекта, находящегося в стеке, из стека выдается ошибка
interface.h
class Wall: public QObject {
Q_OBJECT
public:
double radiusInside;
double radiusOutside;
double Height;
static int indexNumber;
static double coordinateZ;
QString name = "Wall";
Wall();
virtual ~Wall();
friend double GeneratorMonteCarlo();
};
class Disk : public Wall {
public:
double radiusInside;
double radiusOutside;
Disk(double radiusOutside, double radiusInside); // объявляем конструктор
~Disk(); // объявляем деструктор
//const QString name = "Disk";
int index;
};
class Сylinder : public Wall {
public:
double radiusOutside;
double Height;
Сylinder(double radiusOutside, double height);
~Сylinder();
//const QString name = "Cylinder";
int index;
};
template
class Stack {
private:
std::stack elements;
public:
Stack();
void push(T* value){
elements.push(value);
}
std::size_t Size() {
return elements.size();
}
T* top() const {
return elements.top();
}
void pop() {
elements.pop();
}
bool empty() const {
return elements.empty();
}
~Stack() {
while (!elements.empty()){
delete elements.top();
elements.pop();
}
}
};```
but after the element is added, I cannot access the fields of the object that was added, it throws an exception, but there is a way to output these variables, there will be garbage in them
` QString name = stack.top()->name;
if (name == "Cylinder") {
if ((selected_text == "Cylinder" && val1 == (stack.top()->radiusOutside)) ||
(selected_text == "Disk" && val1 == (stack.top()->radiusOutside)) ||
(selected_text == "Disk" && val2 == (stack.top()->radiusInside))) {
return true;`
Подробнее здесь: https://stackoverflow.com/questions/784 ... f-two-chil