【问题标题】:Error : redefinition of default parameter [duplicate]错误:重新定义默认参数 [重复]
【发布时间】:2016-03-11 12:47:40
【问题描述】:

我有两种方法来实现命名:Compute_correlation 和 cca。这就是我定义它们的方式:

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); 
    }

我正在尝试从 main 实现它们,但显示以下错误: 重新定义默认参数。请帮帮我

【问题讨论】:

  • 出现错误是因为你试图重新定义默认参数,不要这样做,错误就会消失
  • 不定义会报错
  • 你得到什么错误?

标签: c++


【解决方案1】:

只需从函数定义的参数列表中删除默认参数的赋值即可。

【讨论】:

  • 谢谢!错误消失了,但是显示了这个错误:fatal error LNK1120: 1 unresolved externals 你有什么想法吗?
  • 只有当你使用了一些编译器无法找到定义的东西时才会发生这种情况。请告诉您遇到链接错误的变量是什么。是的,这个错误与你之前的错误无关。另请参阅链接:link,以获取有关链接错误的更多帮助。
  • 请帮我在哪里可以找到我必须讲述的变量
  • 你必须让我在错误消息中得到这些名字
  • 1> LINK : C:\Users\user\Documents\Visual Studio 2012\Projects\Implementation-CCA\Debug\Implementation-CCA.exe 找不到或不是由最后一个增量链接构建的;执行完整链接 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:致命错误LNK1120:1个未解决的外部==========构建:0成功,1失败,0最新,0跳过==========跨度>
【解决方案2】:

您应该只在声明中设置默认参数,而不是在定义(实现)中。 在您的情况下,删除它们出现在函数实现中的= 0 部分。

The compiler is complaining about my default parameters?

【讨论】:

  • ... 和 = 5= 2 以及 ;-)
  • 谢谢!错误消失了,但显示此错误:致命错误LNK1120:1未解决的外部您对此有任何想法吗? @SpamBot
  • 我们的编码标准是注释掉定义中的默认参数。例如。 unsigned long extra_rank /* = 5 */.当声明位于单独的 .h 文件中时,它可以帮助读者了解默认值是什么。
  • @BryanT 然后在声明中更改了 actual 默认值,并且评论非常无用。
  • @Biffen - 没错,但它也适用于方法参数描述中的任何 cmets。回想起来 - 保持 decl 和任何 cmets 一致就足够了。 (标准不是我的。)
猜你喜欢
  • 1970-01-01
  • 2012-09-21
  • 2021-04-08
  • 2012-12-21
  • 1970-01-01
  • 2011-01-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多