Я иногда использую бывший в качестве тестового стенда, а затем переводит код в мой настоящий проект в 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), чтобы это произошло.
Этой простой настройку неподвижной мой билд! Мне все еще интересно, почему разница в поведении в двух рамках. – sitiposit