私は時々前者をテストベッドとして使い、次にXCodeで実際のプロジェクトにコードを移動します。この場合私にとってはうまくいきません。次のコードは、Coliru(cat /Archive2/48/70c3935989bffb/main.cppを参照)ではコンパイルして実行しますが、XCodeでは実行しません。ここでなぜこのコードはColiruでコンパイルされますが、Xcodeではコンパイルされませんか?
#include <cassert>
template <typename T, typename P>
class Permutation
{
public:
virtual bool operator==(const P& other) const;
// other member functions not listed here use the type T
};
template <typename T>
class SmallPermutation : public Permutation<T, SmallPermutation<T> >
{
public:
SmallPermutation(int i);
virtual bool operator==(const SmallPermutation& other) const;
int code;
// other member functions not listed here use the type T
};
template <typename T>
SmallPermutation<T>::SmallPermutation(int i)
{
code = i;
}
template <typename T>
bool SmallPermutation<T>::operator==(const SmallPermutation& other) const
{
return code == other.code;
}
int main()
{
SmallPermutation<int> a(4);
SmallPermutation<int> b(7);
SmallPermutation<int> c(4);
assert(a == c);
assert(!(a == b));
return 0;
}
は(私は理解していない)XCodeのからのエラーメッセージの一部です:
Undefined symbols for architecture x86_64:
"Permutation<int, SmallPermutation<int> >::operator==(SmallPermutation<int> const&) const", referenced from:
vtable for Permutation<int, SmallPermutation<int> > in permutationTest.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
は、コードに関する標準外の何かがありますか?私が調整する必要があるXCodeにビルド/コンパイル/環境設定がありますか?
背景:私は、同じインターフェースを持ついくつかの(テンプレート)クラスを持っており、すべてが抽象クラスから継承したいと考えています。テンプレートは、この作業を少し難しくします。私はCRTP(Curiously Recurring Template Pattern)というテクニックを使って(おそらく誤って)それを起こさせました。
このシンプルな調整:
またはダミー実装を提供するために!私はまだ2つのフレームワークにおける動作の違いがなぜ疑問です。 – sitiposit