Results 1 to 2 of 2

Thread: About template meta-programming problem with QT

  1. #1
    Join Date
    Feb 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default About template meta-programming problem with QT

    with this code

    Qt Code:
    1. template<int Degree>
    2. PPolynomial<Degree> PPolynomial<Degree>::GaussianApproximation(const double& width)
    3. {
    4. return PPolynomial<Degree-1>::GaussianApproximation().MovingAverage(width);
    5. }
    6.  
    7. template<>
    8. PPolynomial<0> PPolynomial<0>::GaussianApproximation(const double& width)
    9. {
    10. return ConstantFunction(width);
    11. }
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: About template meta-programming problem with QT

    >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 ?

Similar Threads

  1. Phonon and the meta interval
    By huilui in forum Qt Programming
    Replies: 3
    Last Post: 7th February 2012, 06:08
  2. template compilation problem
    By totem in forum Qt Programming
    Replies: 3
    Last Post: 19th October 2010, 14:34
  3. problem with using template classes
    By arbi in forum General Programming
    Replies: 4
    Last Post: 1st September 2010, 13:29
  4. Replies: 4
    Last Post: 25th June 2010, 09:21
  5. problem using template
    By mickey in forum General Programming
    Replies: 6
    Last Post: 18th November 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.