使用局部类型声明的函数已使用但从未定义

时间:2019-07-22 22:45:34

标签: c++

/grid/cva/p4_02/hisham/gcc/ua/Framework/Roman/src/HelperFunction.h:34:6: error: 

我在头文件(HelperFunction.h)中有一个函数声明,如下所示:

template<typename Lambda,typename... Args>
void timeFunction(Lambda lambda, Args... args);

该函数在HelperFunction.cpp文件中的定义如下:

template<typename Lambda, typename... Args>
void timeFunction(Lambda lambda,Args... args) {
    std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
    function(args...);
    std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
    std::cout << duration;
}

主要功能如下:

#include "HelperFunction.h"
int main(){
    auto lambda=[](){trial();};
    timeFunction(lambda);
}

但是出现以下错误:

    'void timeFunction(Lambda, Args ...) [with Lambda = main()::<lambda()>; Args = {}]', declared using local type 'main()::<lambda()>', is used but never defined [-fpermissive]
     void timeFunction(Lambda lambda, Args... args);
          ^~~~~~~~~~~~
    /grid/cva/p4_02/hisham/gcc/ua/Framework/Roman/src/HelperFunction.h:34:6: error: 'void timeFunction(Lambda, Args ...) [with Lambda = main()::<lambda()>; Args = {}]' used but never defined [-Werror]
    cc1plus: all warnings being treated as errors

我只是试图创建一个函数,该函数将使用另一个函数的参数并获取返回所需的毫秒数。尽管进行了研究,但我无法识别错误的含义。它说函数已使用但从未在错误中定义,但我确实定义了它。

0 个答案:

没有答案