Здравствуйте, есть тест класса Polynomial - класс был не шаблонным и тест собирался и работал. Сделал класс шаблонным - получаю огромное количество ошибок undefined reference:
#include "../ntru_main/polynomial.h"
#include <QString>
#include <QtTest>
Q_DECLARE_METATYPE(Polynomial<qint32>)
class PolynomialTest : public QObject
{
Q_OBJECT
public:
PolynomialTest();
private Q_SLOTS:
void multiple_data();
void multiple();
};
PolynomialTest::PolynomialTest()
{
}
void PolynomialTest::multiple_data()
{
QTest::addColumn<Polynomial<qint32> >("left_Polynomial");
QTest::addColumn<Polynomial<qint32> >("right_Polynomial");
QTest::addColumn<Polynomial<qint32> >("result_Polynomial");
QTest::newRow("first") << Polynomial<qint32>({2, -1, 3})
<< Polynomial<qint32>({1, 2, -1})
<< Polynomial<qint32>({0, 0, -1});
QTest::newRow("second") << Polynomial<qint32>({1, -3, 1, 0, 0, 2, -1})
<< Polynomial<qint32>({3, 0, 2, 0, -3, 0, 1})
<< Polynomial<qint32>({4, -10, -1, -3, 1, 14, -5});
}
void PolynomialTest::multiple()
{
QFETCH(Polynomial<qint32>, left_Polynomial);
QFETCH(Polynomial<qint32>, right_Polynomial);
QFETCH(Polynomial<qint32>, result_Polynomial);
QCOMPARE(left_Polynomial * right_Polynomial, result_Polynomial);
}
QTEST_APPLESS_MAIN(PolynomialTest)
#include "test_polynomial.moc"
Ошибки именно в тесте, класс собирается и работает если его вынести в отдельный проект.
test_polynomial.o: In function `PolynomialTest::multiple_data()':
/home/evgeniy/Programming/C++/build-NTRU-Qt_5_4_2-Debug/tests/../../NTRU/tests/test_polynomial.cpp:33: undefined reference to `Polynomial<int>::Polynomial(std::initializer_list<int>)'
/home/evgeniy/Programming/C++/build-NTRU-Qt_5_4_2-Debug/tests/../../NTRU/tests/test_polynomial.cpp:32: undefined reference to `Polynomial<int>::Polynomial(std::initializer_list<int>)'
/home/evgeniy/Programming/C++/build-NTRU-Qt_5_4_2-Debug/tests/../../NTRU/tests/test_polynomial.cpp:31: undefined reference to `Polynomial<int>::Polynomial(std::initializer_list<int>)'
/home/evgeniy/Programming/C++/build-NTRU-Qt_5_4_2-Debug/tests/../../NTRU/tests/test_polynomial.cpp:37: undefined reference to `Polynomial<int>::Polynomial(std::initializer_list<int>)'
/home/evgeniy/Programming/C++/build-NTRU-Qt_5_4_2-Debug/tests/../../NTRU/tests/test_polynomial.cpp:36: undefined reference to `Polynomial<int>::Polynomial(std::initializer_list<int>)'
test_polynomial.o:/home/evgeniy/Programming/C++/build-NTRU-Qt_5_4_2-Debug/tests/../../NTRU/tests/test_polynomial.cpp:35: more undefined references to `Polynomial<int>::Polynomial(std::initializer_list<int>)' follow
make[1]: Leaving directory `/home/evgeniy/Programming/C++/build-NTRU-Qt_5_4_2-Debug/tests'
test_polynomial.o: In function `PolynomialTest::multiple()':
/home/evgeniy/Programming/C++/build-NTRU-Qt_5_4_2-Debug/tests/../../NTRU/tests/test_polynomial.cpp:46: undefined reference to `Polynomial<int>::operator*(Polynomial<int> const&) const'
test_polynomial.o: In function `bool QTest::qCompare<Polynomial<int> >(Polynomial<int> const&, Polynomial<int> const&, char const*, char const*, char const*, int)':
/usr/include/qt5/QtTest/qtestcase.h:284: undefined reference to `Polynomial<int>::operator==(Polynomial<int>) const'
test_polynomial.o: In function `QtMetaTypePrivate::QMetaTypeFunctionHelper<Polynomial<int>, true>::Create(void const*)':
/usr/include/qt5/QtCore/qmetatype.h:714: undefined reference to `Polynomial<int>::Polynomial()'
test_polynomial.o: In function `QtMetaTypePrivate::QMetaTypeFunctionHelper<Polynomial<int>, true>::Construct(void*, void const*)':
/usr/include/qt5/QtCore/qmetatype.h:727: undefined reference to `Polynomial<int>::Polynomial()'
collect2: error: ld returned 1 exit status