implementation of the wall class and its child classes, as well as the stack itself.
here I add classes to the stack and using the isBuildingCorrectly function I check whether I can insert the next object, but when I access the fields of the object that is on the stack from the stack, an error is generated
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 <typename T>
class Stack {
private:
std::stack<T*> 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;`
New contributor
Александр Тымин is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.