I have generic class in .h
file
#include "DictionaryListNode.h"
template<typename KeyType, typename ValueType>
class DictionaryList {
private:
DictionaryListNode<KeyType, ValueType>* head;
public:
DictionaryList();
};
I want to define its constructor in .cpp
file
#include "DictionaryList.h"
template<typename KeyType, typename ValueType>
DictionaryList<KeyType, ValueType>::DictionaryList() {
this->head = nullptr;
}
But I get error, which says nothing about problem
Undefined symbols for architecture arm64:
"DictionaryList<int, int>::DictionaryList()", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
I tried to compile it for x86
, the problem is not in architecture arm64
When I try to define constructor inside class description in header file, it compiles successfully. Like this:
template<typename KeyType, typename ValueType>
class DictionaryList {
private:
DictionaryListNode<KeyType, ValueType>* head;
public:
DictionaryList() {
}
};
So the problem is definitely in constructor in .cpp
file.