PDA

View Full Version : About template meta-programming problem with QT



gaserland
28th February 2011, 02:44
with this code


template<int Degree>
PPolynomial<Degree> PPolynomial<Degree>::GaussianApproximation(const double& width)
{
return PPolynomial<Degree-1>::GaussianApproximation().MovingAverage(width);
}

template<>
PPolynomial<0> PPolynomial<0>::GaussianApproximation(const double& width)
{
return ConstantFunction(width);
}

MSVC 2008 Link error:
1>------ Build started: Project: Protable-Coordinate Measuring Machines, Configuration: Debug Win32 ------
1>Moc'ing mainwindow.h...
1>Compiling...
1>moc_mainwindow.cpp
1>mainwindow.cpp
1>main.cpp
1>Generating Code...
1>Linking...
1>LINK : C:\Users\Suriyong\Documents\Visual Studio 2008\Projects\Protable-Coordinate Measuring Machines\Debug\Protable-Coordinate Measuring Machines.exe not found or not built by the last incremental link; performing full link
1>mainwindow.obj : error LNK2005: "public: static class PPolynomial<0> __cdecl PPolynomial<0>::GaussianApproximation(double const &)" (?GaussianApproximation@?$PPolynomial@$0A@@@SA?AV1 @ABN@Z) already defined in main.obj
1>poisson_reconstruction_2.obj : error LNK2005: "public: static class PPolynomial<0> __cdecl PPolynomial<0>::GaussianApproximation(double const &)" (?GaussianApproximation@?$PPolynomial@$0A@@@SA?AV1 @ABN@Z) already defined in main.obj
1>moc_mainwindow.obj : error LNK2005: "public: static class PPolynomial<0> __cdecl PPolynomial<0>::GaussianApproximation(double const &)" (?GaussianApproximation@?$PPolynomial@$0A@@@SA?AV1 @ABN@Z) already defined in main.obj
1>C:\Users\Suriyong\Documents\Visual Studio 2008\Projects\Protable-Coordinate Measuring Machines\Debug\Protable-Coordinate Measuring Machines.exe : fatal error LNK1169: one or more multiply defined symbols found
1>Build log was saved at "file://c:\Users\Suriyong\Documents\Visual Studio 2008\Projects\Protable-Coordinate Measuring Machines\Protable-Coordinate Measuring Machines\Debug\BuildLog.htm"
1>Protable-Coordinate Measuring Machines - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

What the problem of this code? and what solution can fix this?
Thankyou.

stampede
28th February 2011, 07:40
>mainwindow.obj : error LNK2005: "public: static class PPolynomial<0> __cdecl PPolynomial<0>::GaussianApproximation(double const &)" (?GaussianApproximation@?$PPolynomial@$0A@@@SA?AV1 @ABN@Z) already defined in main.obj
1>poisson_reconstruction_2.obj : error LNK2005: "public: static class PPolynomial<0> __cdecl PPolynomial<0>::GaussianApproximation(double const &)" (?GaussianApproximation@?$PPolynomial@$0A@@@SA?AV1 @ABN@Z) already defined in main.obj
1>moc_mainwindow.obj : error LNK2005: "public: static class PPolynomial<0> __cdecl PPolynomial<0>::GaussianApproximation(double const &)" (?GaussianApproximation@?$PPolynomial@$0A@@@SA?AV1 @ABN@Z) already defined in main.obj
Looks like you have multiple definitions of the specialized class. Where is this template code defined ? Does it have an include guard ?