Ok chłopaki ... Mam następujące klasySzablon konstruktora klasy
#include <functional>
template <typename TValue, typename TPred = std::less<TValue>>
class BinarySearchTree {
struct TNode {
TValue value;
TNode *pLeft;
TNode *pRight;
};
public:
BinarySearchTree();
~BinarySearchTree();
. . .
private:
TNode *pRoot;
. . .
};
potem w moim pliku .cpp i zdefiniował konstruktor/dtor takiego:
template <typename TValue, typename TPred>
BinarySearchTree<TValue, TPred>::BinarySearchTree() : pRoot(0) {}
template <typename TValue, typename TPred>
BinarySearchTree<TValue, TPred>::~BinarySearchTree() {
Flush(pRoot);
}
mój Główną funkcją:
int main() {
BinarySearchTree<int> obj1;
return 0;
}
i dostaję następujący błąd podnośnik:
public: __thiscall BinarySearchTree<int,struct std::less<int>>::BinarySearchTree<int,struct std::less<int> >(void)
Próbowałem umieścić definicję konstruktora w pliku nagłówkowym i nie otrzymuję błędu. tylko wtedy, gdy spróbuję zdefiniować to w pliku cpp.
Odpowiedź na twoje pytanie jest [tutaj] (http://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file) - przepraszam, niewłaściwy link w zamkniętym głosowaniu –