Important: Please read the Qt Code of Conduct -

[Moved] Template error

  • 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": ," .cpp file": . Any help is good .

    [Moved to C++ Gurus forum; mlong]

  • 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
    #include "matrix.cpp"
    //#define export /export/


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

  • 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

  • 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.

  • 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
    // ...

Log in to reply