I'm going insane over this issue and I can't find out what's going on. I've been away from C++ programming for a couple of years and apparently I'm missing something. I currently have the following files:
Node.h
#ifndef LIGHTHOUSE_NODE_H
#define LIGHTHOUSE_NODE_H
#include <iostream>
#include "Problem.cpp"
using namespace std;
template <class ActionType, class StateType>
class Node {
private:
Node<ActionType, StateType>* parent;
ActionType* action;
StateType* state;
unsigned int cost;
public:
Node(Node<ActionType, StateType>* parent, ActionType* action, StateType* state, unsigned int cost);
Node();
~Node();
Node* makeNode( Node<ActionType, StateType>* parent, ActionType* action, Problem<ActionType, StateType> problem );
Node* getParent();
ActionType* getAction();
StateType* getState();
unsigned int getCost();
bool operator == (Node<ActionType, StateType> tbCompared);
virtual string toString();
};
#endif
Node.cpp:
/**
* Declaration of non virtual methods within Node class, I don't think this is what gives problems
**/
Problem.h
#ifndef LIGHTHOUSE_PROBLEM_H
#define LIGHTHOUSE_PROBLEM_H
#include "Node.h"
template<class ActionType, class StateType>
class Problem {
private:
StateType* initialState;
public:
Problem();
explicit Problem( StateType* initialState );
~Problem();
StateType* getInitialState();
void setInitialState( StateType* initialState );
virtual ActionType** actions( StateType* state );
virtual StateType* result( ActionType* action, StateType* state );
virtual bool goalTest( StateType* state );
virtual unsigned int cost( ActionType* action, StateType* state );
};
#endif
Problem.cpp
#include "Problem.h"
template<class ActionType, class StateType>
Problem<ActionType, StateType>::Problem(StateType *initialState) {
this->initialState = initialState;
}
template<class ActionType, class StateType>
Problem<ActionType, StateType>::Problem() {
this(nullptr);
}
template<class ActionType, class StateType>
Problem<ActionType, StateType>::~Problem() {
delete initialState;
}
template<class ActionType, class StateType>
StateType *Problem<ActionType, StateType>::getInitialState() {
return this->initialState;
}
template<class ActionType, class StateType>
void Problem<ActionType, StateType>::setInitialState(StateType *initialState) {
this->initialState = initialState;
}
For completeness' sake I include the errors log I get.
**Error log: **
FAILED: CMakeFiles/Lighthouse.dir/GenericProblem/Problem.cpp.obj
C:\PROGRA~1\JETBRA~1\CLION2~1.1\bin\mingw\bin\G__~1.EXE -g -std=gnu++20 -MD -MT CMakeFiles/Lighthouse.dir/GenericProblem/Problem.cpp.obj -MF CMakeFiles\Lighthouse.dir\GenericProblem\Problem.cpp.obj.d -o CMakeFiles/Lighthouse.dir/GenericProblem/Problem.cpp.obj -c C:/Users/nicco/CLionProjects/Lighthouse/GenericProblem/Problem.cpp
In file included from C:/Users/nicco/CLionProjects/Lighthouse/GenericProblem/Node.h:6,
from C:/Users/nicco/CLionProjects/Lighthouse/GenericProblem/Problem.h:5,
from C:/Users/nicco/CLionProjects/Lighthouse/GenericProblem/Problem.cpp:1:
C:/Users/nicco/CLionProjects/Lighthouse/GenericProblem/Problem.cpp:4:1: error: 'Problem' does not name a type
4 | Problem<ActionType, StateType>::Problem(StateType *initialState) {
| ^~~~~~~
C:/Users/nicco/CLionProjects/Lighthouse/GenericProblem/Problem.cpp:9:1: error: 'Problem' does not name a type
9 | Problem<ActionType, StateType>::Problem() {
| ^~~~~~~
C:/Users/nicco/CLionProjects/Lighthouse/GenericProblem/Problem.cpp:14:1: error: 'Problem' does not name a type
14 | Problem<ActionType, StateType>::~Problem() {
| ^~~~~~~
C:/Users/nicco/CLionProjects/Lighthouse/GenericProblem/Problem.cpp:19:19: error: expected initializer before '<' token
19 | StateType *Problem<ActionType, StateType>::getInitialState() {
| ^
C:/Users/nicco/CLionProjects/Lighthouse/GenericProblem/Problem.cpp:24:13: error: expected initializer before '<' token
24 | void Problem<ActionType, StateType>::setInitialState(StateType *initialState) {
| ^
In file included from C:/Users/nicco/CLionProjects/Lighthouse/GenericProblem/Problem.h:5,
from C:/Users/nicco/CLionProjects/Lighthouse/GenericProblem/Problem.cpp:1:
C:/Users/nicco/CLionProjects/Lighthouse/GenericProblem/Node.h:23:86: error: 'Problem' has not been declared
23 | Node* makeNode( Node<ActionType, StateType>* parent, ActionType* action, Problem<ActionType, StateType> problem );
| ^~~~~~~
C:/Users/nicco/CLionProjects/Lighthouse/GenericProblem/Node.h:23:93: error: expected ',' or '...' before '<' token
23 | Node* makeNode( Node<ActionType, StateType>* parent, ActionType* action, Problem<ActionType, StateType> problem );
| ^
[3/4] Building CXX object CMakeFiles/Lighthouse.dir/GenericProblem/Node.cpp.obj
ninja: build stopped: subcommand failed.
I can't get my head around the reason why Problem would be considered undefined?