Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. [Moved] Template error
Forum Updated to NodeBB v4.3 + New Features

[Moved] Template error

Scheduled Pinned Locked Moved C++ Gurus
6 Posts 3 Posters 2.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr.FreakyJo
    wrote on last edited by
    #1

    I don't know if I can post here help on some code errors that are not linked with qt but I want to implement this code in my app.In my app I need to use the Munkres assignment algorithm .I found some free source code .In my compiler I get an error.It has to do with templates.I haven't learn about templates so this is why it's beyond me.I use Microsoft Visual Studio 2010.
    Here is the error error C2995: 'Matrix<T>::Matrix(void)' : function template has already been defined.
    Here are the links to the header and the implementation source code :" header":https://github.com/saebyn/munkres-cpp/blob/master/src/matrix.h ," .cpp file":https://github.com/saebyn/munkres-cpp/blob/master/src/matrix.cpp . Any help is good .

    [Moved to C++ Gurus forum; mlong]

    1 Reply Last reply
    0
    • M Offline
      M Offline
      m.derempoukas
      wrote on last edited by
      #2

      I might miss the big picture here but i don't see the point of including matrix.cpp from matrix.h
      try commenting out these
      @#ifndef USE_EXPORT_KEYWORD
      #include "matrix.cpp"
      //#define export /export/
      #endif

      @

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mr.FreakyJo
        wrote on last edited by
        #3

        Tried that and the linker doesn't see matrix.cpp after anymore.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fcrochik
          wrote on last edited by
          #4

          In the past with Visual C++ the recommended way was to have the "implementation of the methods" on the .h file (pretty much like a java or c# file). I assume that is the goal of including a .cpp file into a .h... you are probably getting the error because the matrix.cpp is also including the matrix.h

          Certified Specialist & Qt Ambassador <a href="http://www.crochik.com">Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop... Qt everywhere!</a>

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mr.FreakyJo
            wrote on last edited by
            #5

            Removing the #include "matrix.h" it's also not good.The linker doesn't see in compiling time I think matrix.h because I get errors like this:

            @1>matrix.cpp(25): error C2143: syntax error : missing ';' before '<'
            1>matrix.cpp(25): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
            1>matrix.cpp(25): error C2988: unrecognizable template declaration/definition
            1>matrix.cpp(25): error C2059: syntax error : '<'
            1>matrix.cpp(32): error C2143: syntax error : missing ';' before '{'
            1>matrix.cpp(32): error C2447: '{' : missing function header (old-style formal list?)@

            And a few more like this for the next function and then a fatal error.

            1 Reply Last reply
            0
            • F Offline
              F Offline
              fcrochik
              wrote on last edited by
              #6

              I would "merge" the two files into the matrix.h .... I am pretty sure that you need to move the implementation of the methods to "inside the class" declaration, something like

              @
              class Matrix {
              // use signature from .h
              void myethod() {
              //however was declared on the cpp file
              // ...
              }
              ...
              };
              @

              Certified Specialist & Qt Ambassador <a href="http://www.crochik.com">Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop... Qt everywhere!</a>

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved