2 つのクラスのコンパイル中に問題が発生しました。
MemoryTrie.h:
#ifndef MEMORYTRIE_H
#define MEMORYTRIE_H
template <typename T>
class MemoryTrie
{
public:
...
T & operator [](const char * key);
private:
...
};
#endif /* MEMORYTRIE_H */
MemoryTrie.cpp:
#include "MemoryTrie.h"
template <typename T>
T & MemoryTrie<T>::operator [](const char * key)
{
...
}
OutputFileTrie.h:
#ifndef OUTPUTFILETRIE_H
#define OUTPUTFILETRIE_H
#include "MemoryTrie.h"
template <typename T>
class OutputFileTrie
{
public:
T & operator [](const char * key);
private:
MemoryTrie<T> memoryTrie;
};
#endif /* OUTPUTFILETRIE_H */
OutputFileTrie.cpp:
#include "OutputFileTrie.h"
template <typename T>
T & OutputFileTrie<T>::operator [](const char * key)
{
return memoryTrie[key];
}
そして、主に次のとおりです。
OutputFileTrie<int> trie;
リンカーは次のように述べています: OutputFileTrie.h:9: `MemoryTrie::MemoryTrie()' への未定義の参照。次の 4 つのコマンドだけを実行しました。
g++ -Wall -pedantic -g -c MemoryTrie.cpp
g++ -Wall -pedantic -g -c OutputFileTrie.cpp
g++ -Wall -pedantic -g -c main.cpp
g++ MemoryTrie.o OutputFileTrie.o main.o -o out
私はそれを正しくやっていますか?私が見逃した間違いはありますか?助けてくれてありがとう。