Почему не включается .hpp файл в CLion?
fhp/node.hpp:
#ifndef FIBONACCIHEAP__NODE_HPP_
#define FIBONACCIHEAP__NODE_HPP_
namespace fhp {
template<typename T>
class node {
private:
void init();
public:
T key;
node<T>* left;
node<T>* right;
node<T>* parent;
node<T>* child;
int degree;
bool mark;
explicit node(T);
void add_child(node<T>*);
};
template<typename T>
void unite(node<T>*, node<T>*);
}
#endif //FIBONACCIHEAP__NODE_HPP_
fhp/node.cpp:
#include "node.hpp"
namespace fhp {
template<typename T>
void node<T>::init() {
key = 0;
left = right = this;
parent = child = this;
degree = 0;
mark = false;
}
template<typename T>
node<T>::node(T val) {
init();
key = val;
}
template<typename T>
void unite(node<T>* to_left, node<T>* to_right) {
if (!to_left)
to_left = to_right;
if (!to_right)
return;
node<T>* l = to_right->left;
node<T>* r = to_left->right;
to_left->right = to_right;
to_right->left = to_left;
l->right = r;
r->left = l;
}
template<typename T>
void node<T>::add_child(node<T>* new_child) {
if (this->child == this)
this->child = new_child;
else
unite(this->child, new_child);
new_child->parent = this;
++this->degree;
}
}
main.cpp:
#include "fhp/node.hpp"
int main() {
auto nd_1 = new fhp::node<int>(4);
auto nd_2 = new fhp::node<int>(5);
fhp::unite(nd_1, nd_2);
delete nd_1;
delete nd_2;
return 0;
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.16)
project(FibonacciHeap)
set(CMAKE_CXX_STANDARD 17)
add_executable(FibonacciHeap main.cpp fhp/node.hpp fhp/node.cpp)
Вот лог ошибки:
[ 33%] Linking CXX executable FibonacciHeap
/usr/bin/ld: CMakeFiles/FibonacciHeap.dir/main.cpp.o: in function main': /mnt/c/Users/nikmy/OneDrive/Рабочий стол/FibonacciHeap/main.cpp:4: undefined reference to fhp::node::node(int)'
/usr/bin/ld: /mnt/c/Users/nikmy/OneDrive/Рабочий стол/FibonacciHeap/main.cpp:5: undefined reference to fhp::node<int>::node(int)' /usr/bin/ld: /mnt/c/Users/nikmy/OneDrive/Рабочий стол/FibonacciHeap/main.cpp:6: undefined reference to void fhp::unite(fhp::node, fhp::node)'
collect2: error: ld returned 1 exit status
Не могу понять, в чём проблема. Если включать fhp/node.cpp, то всё работает.