Dlib r_squared C2059错误

时间:2016-08-26 04:51:53

标签: c++ qt dlib

在尝试让Dlib库在QT中运行一整天之后,我终于开始运行并且认为我在家是免费的。我试着调用r_squared函数并在某些向量上测试它并且它不允许我将它设置为等于打印输出的双x,也不让我cout(qDebug()<< ... )在QT中,函数r_squared。下面我已经复制了我的代码以及标题中的功能,任何人都可以告诉我不仅仅是我在这里做错了什么,还有什么问题?所有标题/来源都已正确包含在内。

VECTORS:

std::vector<double> avec;
std::vector<double> bvec;

avec.push_back(1);
avec.push_back(2);
avec.push_back(3);
avec.push_back(4);
bvec.push_back(5);
bvec.push_back(6);
bvec.push_back(7);
bvec.push_back(1);

BUILDS AND RUNS OK:

double x;

double r_squared (
       const std::vector<double>& avec,
       const std::vector<double>& bvec
   );

不工作(QT&#34中的作业和qDebug()&#34; cout;

double x;
x = r_squared (
            const std::vector<double>& avec,
            const std::vector<double>& bvec
        );
qDebug() << x; 
qDebug() << r_squared(enter actual parameters)

erroe C2059收到了上面的块

自DLIB定义的代码

  template <
    typename T, 
    typename alloc
    >

double r_squared (
    const std::vector<T,alloc>& a,
    const std::vector<T,alloc>& b
)
{
    // make sure requires clause is not broken
    DLIB_ASSERT(a.size() == b.size() && a.size() > 1,
                "\t double r_squared(a,b)"
                << "\n\t a and b must be the same length and have more than one element."
                << "\n\t a.size(): " << a.size()
                << "\n\t b.size(): " << b.size()
    );

    return std::pow(correlation(a,b),2.0);
}

我也试过

x = r_squared (
       &avec,
       &bvec
   );

并收到错误消息C3861:找不到r_squared标识符。当我查看标题时,它被定义。

AND HERES THE MAIN.CPP

#include "dlib3.h"
#include <QApplication>
#include <QDebug>
#include "dlib-master/dlib/statistics.h"


int main(int argc, char *argv[])
{
QApplication a(argc, argv);
dlib3 w;

std::vector<double> avec;
std::vector<double> bvec;

avec.push_back(1);
avec.push_back(2);
avec.push_back(3);
avec.push_back(4);
bvec.push_back(5);
bvec.push_back(6);
bvec.push_back(7);
bvec.push_back(1);

double x;

x = r_squared (
       &avec,
       &bvec
   );



w.show();
return a.exec();
}

1 个答案:

答案 0 :(得分:1)

逐一完成这些:

double r_squared (
       const std::vector<double>& avec,
       const std::vector<double>& bvec
   );

不调用函数。它尝试forward declare r_squared函数与dlib / statistics.h中的函数略有不同。编译,但在运行时不执行任何操作。不是你想做的。

x = r_squared (
        const std::vector<double>& avec,
        const std::vector<double>& bvec
    );

混合函数调用和函数声明语法,简单不正确。它没有做,因为,正如OP所知,它没有编译。

x = r_squared (
       &avec,
       &bvec
   );

使用指向2个向量的指针调用r_squared。这意味着编译器会寻找

template <typename T, typename alloc>
double r_squared (
    const std::vector<T,alloc>* a,
    const std::vector<T,alloc>* b
);

注意*代替&,并找到

template <typename T, typename alloc>
double r_squared (
    const std::vector<T,alloc>& a,
    const std::vector<T,alloc>& b
);

不匹配,因此编译器找不到r_squared。不是你要求的r_squared

解决方案:

这有尝试学习C ++的气味,盲目地复制代码而不了解代码在做什么,如何以及为什么。 Get a good book,阅读它,完成示例,学习C ++。 OP目前正在做的是浪费时间。

然后在不使用参数的address-of operator的情况下调用该函数。

x = r_squared(avec, bvec);

修改

正如Evgeniy在上面的评论中指出的那样,还需要遵守dlib命名空间。正确的电话会是

x = dlib::r_squared(avec, bvec);