#‘class’ has no member named ‘variable’

1 messages · Page 1 of 1 (latest)

mint river
#

I have this, with the error of the title of the post

fair islandBOT
#

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.

regal vault
#

we need a bit more context honestly

mint river
regal vault
#

can we actually get the code and not a screenshot

#

that reads much nicer

mint river
#

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;    
}
regal vault
#

and what is the actual error it throws?

mint river
#

sorry forgot to say where

#

it throws the same with firstX -> first.getNext();

regal vault
#

well what is firtstx?

mint river
regal vault
#

no what is it

#

oh I am blind

#

what do you think you're re doing in this line?
firstX -> first.getNext();

mint river
regal vault
#

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

mint river
#

ohh

#

so i changed as

Node* firstX = first;
firstX = first->getNext();
free(firstX);```
snow vigil
#

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?

mint river
#

!solved