「main.cpp」の8行目でエラーが発生するべきではありませんか?
- デストラクタを使用していません。
- 「const」キーワードと関係があると思います。
main.cpp:
#include "stack.hpp"
int main() {
node* firstnode = new node(NULL, 5);
std::cout << firstnode -> getvariable() << std::endl;
node* secondnode = new node(NULL, 10);
std::cout << secondnode -> getvariable() << std::endl;
delete firstnode;
std::cout << firstnode -> getvariable() << std::endl;
return 0;
}
stack.hpp:
#ifndef stack_hpp
#define stack_hpp
#include <iostream>
class node {
public:
node(node* nextnode, int variablevalue);
void setvariable(const int variablevalue);
const int getvariable() const;
private:
node* nextnodelink;
int variable;
};
#endif
stack.cpp:
#include "stack.hpp"
node::node(node* nextnode, int variablevalue)
: nextnodelink(nextnode), variable(variablevalue) {
}
const int node::getvariable() const {
return variable;
}