Ok ragazzi ... ho seguente classemodello di classe costruttore
#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;
. . .
};
poi nel mio file cpp ho definito la ctor/dtor come questo:
template <typename TValue, typename TPred>
BinarySearchTree<TValue, TPred>::BinarySearchTree() : pRoot(0) {}
template <typename TValue, typename TPred>
BinarySearchTree<TValue, TPred>::~BinarySearchTree() {
Flush(pRoot);
}
mia funzione principale:
int main() {
BinarySearchTree<int> obj1;
return 0;
}
ed ottengo errore seguente collegamento:
public: __thiscall BinarySearchTree<int,struct std::less<int>>::BinarySearchTree<int,struct std::less<int> >(void)
ho provato a mettere la definizione del costruttore nel file di intestazione e non ottengo alcun errore. solo se provo a definirlo nel file cpp.
La risposta alla tua domanda è [qui] (http://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file) - scusa, collegamento errato allo stretto voto –