1

I have two methods to implement named : Compute_correlation and cca. This is how I define them :

namespace dlib
{
     template <typename T>matrix<typename T::type,0,1> compute_correlations (
        const matrix_exp<T>& L,
        const matrix_exp<T>& R
       );

      template <typename T>matrix<T,0,1> cca (
        const matrix<T>& L,
        const matrix<T>& R,
        matrix<T>& Ltrans,
        matrix<T>& Rtrans,
        unsigned long num_correlations,
        unsigned long extra_rank = 5,
        unsigned long q = 2,
        double regularization = 0
       );

    int _tmain(int argc, _TCHAR* argv[]) {...}
    template <
        typename T
        >
    matrix<typename T::type,0,1> compute_correlations (
        const matrix_exp<T>& L,
        const matrix_exp<T>& R
    )
    {
        DLIB_ASSERT( L.size() > 0 && R.size() > 0 && L.nr() == R.nr(), 
            "\t matrix compute_correlations()"
            << "\n\t Invalid inputs were given to this function."
            << "\n\t L.size(): " << L.size()
            << "\n\t R.size(): " << R.size()
            << "\n\t L.nr():   " << L.nr()
            << "\n\t R.nr():   " << R.nr()
            );

        typedef typename T::type type;
        matrix<type> A, B, C;
        A = diag(trans(R)*L);
        B = sqrt(diag(trans(L)*L));
        C = sqrt(diag(trans(R)*R));
        A = pointwise_multiply(A , reciprocal(pointwise_multiply(B,C)));
        return A;
    }

    template <typename T>
    matrix<T,0,1> cca (
        const matrix<T>& L,
        const matrix<T>& R,
        matrix<T>& Ltrans,
        matrix<T>& Rtrans,
        unsigned long num_correlations,
        unsigned long extra_rank = 5,
        unsigned long q = 2,
        double regularization = 0
    )
    {
        DLIB_ASSERT( num_correlations > 0 && L.size() > 0 && R.size() > 0 && L.nr() == R.nr() &&
            regularization >= 0, 
            "\t matrix cca()"
            << "\n\t Invalid inputs were given to this function."
            << "\n\t num_correlations: " << num_correlations 
            << "\n\t regularization:   " << regularization 
            << "\n\t L.size(): " << L.size()
            << "\n\t R.size(): " << R.size()
            << "\n\t L.nr():   " << L.nr()
            << "\n\t R.nr():   " << R.nr()
            );

        using std::min;
        const unsigned long n = min(num_correlations, (unsigned long)min(R.nr(),min(L.nc(), R.nc())));
        return impl_cca(L,R,Ltrans, Rtrans, num_correlations, extra_rank, q, n, regularization); 
    }

I am trying to implement them from main, but the following error is shown: redefinition of default parameter. Please help me

H.Y
  • 23
  • 1
  • 7

2 Answers2

4

Just remove the assignment for the default parameters from the argument list of the function definition.

  • Thank you! The error is gone, but this error is shown: fatal error LNK1120: 1 unresolved externals Do you have any idea about it? – H.Y Mar 11 '16 at 13:10
  • This happens only when you have used some things for which compiler is not able to locate the definition. Please tell what are the variables for which you are getting linking errors. And yes the this error is independent of your previous error. Also refer the link: [link](http://stackoverflow.com/questions/21361308/fatal-error-lnk1120-4-unresolved-externals) for more help on linking errors. – Kaushalendra Mishra Mar 11 '16 at 13:16
  • please help me where to find the varibales I have to tell about – H.Y Mar 11 '16 at 13:34
  • You must me getting those names in error messages – Kaushalendra Mishra Mar 11 '16 at 13:43
  • 1> LINK : C:\Users\user\Documents\Visual Studio 2012\Projects\Implementation-CCA\Debug\Implementation-CCA.exe not found or not built by the last incremental link; performing full link 1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup 1>C:\Users\user\Documents\Visual Studio 2012\Projects\Implementation-CCA\Debug\Implementation-CCA.exe : fatal error LNK1120: 1 unresolved externals ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== – H.Y Mar 11 '16 at 13:48
  • This is the output of running – H.Y Mar 11 '16 at 13:52
  • You might have picked the wrong type of the project at the start in your visual studio. what project did you choose? Are you developing a independent application ( a smaller application) kindly create a new project in visual studio as console application --> empty project and then try to write your code and compile. – Kaushalendra Mishra Mar 11 '16 at 13:59
  • I tried this, new project, empty but the same error still occured – H.Y Mar 11 '16 at 14:08
  • My apologies for my previous comment. kindly place your main function (i.e. int _tmain(int argc, _TCHAR* argv[]) {...}) outside the namespace in your existing project. i.e. place this main outside namespace "dlib". This should work. – Kaushalendra Mishra Mar 11 '16 at 14:19
  • in this way, the matrix becomes not defined.. :( – H.Y Mar 11 '16 at 14:24
  • For that you can have forward declaration for your class or move the class declaration in .h header file and include that header. – Kaushalendra Mishra Mar 11 '16 at 14:25
  • You might consider writting new question for your new problem when it gets solved. – Kaushalendra Mishra Mar 11 '16 at 14:29
  • I have a header file and it is included, but the matrix still not defined.. I will write a new question. – H.Y Mar 11 '16 at 14:34
  • As it is a template class so every type you are using must be forward declared. You might check it by reducing your code only in type of the matrix class and forward declare and then forward declare all the types or simple solution to this problem is moving all the function definition (yes i said definition) to the header file so that all type variants of this class are ready. – Kaushalendra Mishra Mar 11 '16 at 14:40
  • Please this is the new question: http://stackoverflow.com/questions/35942947/error-fatal-error-lnk1120-1-unresolved-externals – H.Y Mar 11 '16 at 14:42
  • Can you check your facebook inbox please @Kaushalendra – H.Y Mar 13 '16 at 10:07
  • Hey @H.Y did not get any, you might have found the different guy. – Kaushalendra Mishra Mar 13 '16 at 11:07
4

You should set default parameters only in the declaration, not in the definition (implemenation). In your case, remove the = 0 parts where their appear in the function implementation.

The compiler is complaining about my default parameters?

Community
  • 1
  • 1
SpamBot
  • 1,438
  • 11
  • 28
  • 2
    ... and `= 5` and `= 2` as well ;-) – Angew is no longer proud of SO Mar 11 '16 at 12:52
  • Thank you! The error is gone, but this error is shown: fatal error LNK1120: 1 unresolved externals Do you have any idea about it? @SpamBot – H.Y Mar 11 '16 at 12:55
  • Our coding standard was to comment out the default parameters in the definition. E.g. unsigned long extra_rank /* = 5 */. When the declaration is in a separate .h file, it helps the reader know what the default is. – BryanT Mar 11 '16 at 12:57
  • 1
    @BryanT And then the *actual* default value is changed in the declaration, and the comment is disastrously unhelpful. – Biffen Mar 11 '16 at 13:00
  • @Biffen - that's true, but it also applies to any comments in the method's parameter descriptions. In retrospect - keeping the decl and any comments in agreement is enough. (The standards weren't mine.) – BryanT Mar 11 '16 at 13:19