#‘class’ has no member named ‘variable’
1 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
we need a bit more context honestly
this is Node.cpp
#include "Node.h"
#include <iostream>
Node::Node(int _value){
value = _value;
}
Node::~Node(){
}
Node* Node::getNext(){
return next;
}
void Node::setNext(Node* Node){
Node = Node;
}
int Node::getValue(){
return value;
}
and this Stack.cpp
#include <iostream>
#include "Node.h"
#include "Stack.h"
Stack::Stack(){
first = nullptr;
quantity = 0;
}
Node* Stack::Top(){
return first;
}
void Stack::Push(int value){
Node node = Node(value);
quantity++;
if(quantity == 0){
first = &node;
}else{
node.setNext(first);
first = &node;
}
}
void Stack::Pop(){
if(quantity != 0){
Node* firstX = first;
firstX -> first.getNext();
free(firstX);
}
}
bool Stack::isEmpty(){
if(quantity > 0){
return false;
}
return true;
}
void Stack::setQuantity(int _quantity){
quantity = _quantity;
}
int Stack::getQuantity(){
return quantity;
}
and what is the actual error it throws?
well what is firtstx?
i created that to not lose the reference of first to after that delete it from memory
no what is it
oh I am blind
what do you think you're re doing in this line?
firstX -> first.getNext();
i am assigning to firstX the "second" node in stack
nope
-> does nothing like that
asignment is =
-> is for operating on pointer types
like first->getNext() is fine as it's equal to something like a.foo() where a is not a pointer type
ohh
so i changed as
Node* firstX = first;
firstX = first->getNext();
free(firstX);```
not enough information
you haven't shown your headers
how are we to know what members your class does and doesn't have if we can't see the class?
!solved