简体   繁体   English

没有匹配的 function 调用 'std::vector::push_back(<brace-enclosed initializer list> )'</brace-enclosed>

[英]no matching function for call to ‘std::vector::push_back(<brace-enclosed initializer list>)’

I am quite new to object oriented programming.我对面向 object 的编程很陌生。 I'm trying to modularize a code in a class format in order to make things easy to understand and make the code extendable.我正在尝试以 class 格式模块化代码,以使事情易于理解并使代码可扩展。

I am stuck with this error:我被这个错误困住了:

   Description  Resource    Path    Location    Type
make: *** [src/interface.o] Error 1 Emulation-SW    /virtualization_proj        C/C++ Problem
make: *** Waiting for unfinished jobs....   Emulation-SW    /virtualization_proj        C/C++ Problem
no matching function for call to ‘std::vector<std::vector<unsigned char, std::allocator<unsigned char> >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > >::push_back(<brace-enclosed initializer list>)’  interface.h /virtualization_proj/src    line 58 C/C++ Problem
recipe for target 'src/interface.o' failed  makefile    /virtualization_proj/Emulation-SW   line 57 C/C++ Problem

The error looks in the IDE as below: IDE 中的错误如下所示:

图片

Can someone help in resolving this error?有人可以帮助解决此错误吗?

class INTERFACE{
   
    public:
    
    std::vector<cl::Device> devices;
    cl::Device device;
    std::vector<cl::Platform> platforms;
    cl::Context context;
    cl::CommandQueue q;

    cl::Program::Binaries bins;
    char *buf;
    unsigned nb;
    
    cl::Program program;

    int push_xclbinFile_to_FPGA(){
      bins.push_back({buf,nb});  // Push_back function is not getting recognized
      devices.resize(1);
      program= cl::Program(context, devices, bins);
      return 1;

    }
 
};

Edit编辑

To make the question more clear, these lines work completely fine when I execute them from the main() function as below.为了使问题更清楚,当我从main() function 执行它们时,这些行完全正常,如下所示。 I hope this will clarify the question a little more.我希望这能进一步澄清这个问题。

图片

Edit编辑

The main file code is as below: main文件代码如下:

int main(int argc, char* argv[]) {


    // Compute the size of array in bytes
     INTERFACE i_obj;
     size_t size_in_bytes= i_obj.compute_size_in_bytes();

    // Finding the device
     int device_found= i_obj.finding_platform();
     if(device_found==0){
         std::cout<< "Device found successfully" << std::endl;
     }

    // Creating Context and Command Queue for selected device
    cl::Context context(i_obj.devices);
    cl::CommandQueue q(context, i_obj.device, CL_QUEUE_PROFILING_ENABLE);
    i_obj.context= context;
    i_obj.q= q;



     VMGR *vm=new VMGR();
     vm->initialize_mq();             // Creating the Queue1


    while(1){


    std::vector<std::string> numbers = vm->run();

    int st=i_obj.buffer_values();


        //setting input data

        if (numbers.size()!=0){



            if(numbers[2]=="SUB"){
//
                    // Read the xclbin file
                  int status_xclbin_read= i_obj.reading_the_xclbinFile(vm);

                 //  Process the read Data

                  i_obj.bins.push_back({i_obj.buf,i_obj.nb});

                  (i_obj.devices).resize(1);



                  // Push the xclbin file into the FPGA
              cl::Program program(i_obj.context, i_obj.devices, i_obj.bins);


                 // This call will get the kernel object from program. A kernel is an
                    // OpenCL function that is executed on the FPGA.
                  i_obj.krnl_vector_sub= cl::Kernel(program,"krnl_vsub");


                int narg=0;

                 // set the kernel Arguments
                i_obj.krnl_vector_sub.setArg(narg++,i_obj.buffer_a);
                i_obj.krnl_vector_sub.setArg(narg++,i_obj.buffer_b);

                i_obj.krnl_vector_sub.setArg(narg++,i_obj.buffer_result);

                i_obj.krnl_vector_sub.setArg(narg++,api::DATA_SIZE);
                //We then need to map our OpenCL buffers to get the pointers
                i_obj.ptr_a = (int *) (i_obj.q).enqueueMapBuffer (i_obj.buffer_a , CL_TRUE , CL_MAP_WRITE , 0, size_in_bytes);
                i_obj.ptr_b = (int *) (i_obj.q).enqueueMapBuffer (i_obj.buffer_b , CL_TRUE , CL_MAP_WRITE , 0, size_in_bytes);

                i_obj.ptr_result = (int *) (i_obj.q).enqueueMapBuffer (i_obj.buffer_result , CL_TRUE , CL_MAP_READ , 0, size_in_bytes);

                i_obj.bins.clear();




            }

        (i_obj.q).finish();




           


    }

    return 0;


}

bins.push_back({buf,nb}) makes no sense. bins.push_back({buf,nb})没有意义。 Because of that the compiler can't figure out what type {buf,nb} is supposed to be.因此,编译器无法确定{buf,nb}应该是什么类型。

Based on your error message, bins is a std::vector<std::vector<unsigned char>> , which means bins.push_back needs you to pass it a std::vector<unsigned char> .根据您的错误消息, binsstd::vector<std::vector<unsigned char>> ,这意味着bins.push_back需要您将其传递给std::vector<unsigned char> {buf,nb} can't be converted to a std::vector<unsigned char> though, since neither buf , nor nb are unsigned char s (one is a char* and the other an unsigned int ). {buf,nb}不能转换为std::vector<unsigned char>但是,因为bufnb都不是unsigned char s(一个是char*而另一个是unsigned int )。

Note that the documentation for the relevant cl::Program constructor appears to be incorrect.请注意,相关cl::Program构造函数的文档似乎不正确。 It is documented to accept a vector of (bin, size) pairs, but it does not.它被记录为接受(bin, size)对的向量,但事实并非如此。 It just accepts a vector of vectors containing binary data.它只接受包含二进制数据的向量向量。 std::vector knows its own size, so that doesn't need to be passed separately. std::vector知道自己的大小,因此不需要单独传递。 Looking at the code it appears that documentation was once correct, but the interface has changed based on the preprocessor conditionals in that constructor.查看代码,似乎文档曾经是正确的,但接口已根据该构造函数中的预处理器条件发生更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:没有匹配的 function 调用 'std::vector<pet*> ::向量(<brace-enclosed initializer list> )'</brace-enclosed></pet*> - error: no matching function for call to 'std::vector<Pet*>::vector(<brace-enclosed initializer list>)' 没有匹配的 function 调用 'std::exception::exception(<brace-enclosed initializer list> )</brace-enclosed> - no matching function for call to ‘std::exception::exception(<brace-enclosed initializer list>) 使用std :: min时发生错误“没有匹配函数调用&#39;min( <brace-enclosed initializer list> )“” - Error when using std::min “no matching function for call to ‘min(<brace-enclosed initializer list>)’” 无法从大括号括起来的初始化列表转换为std :: vector - Could not convert from brace-enclosed initializer list to std::vector 正确的线程调用语法? 错误:没有匹配调用std :: thread :: thread( <brace-enclosed initializer list> ) - Proper thread call syntax? error: no matching call to std::thread::thread(<brace-enclosed initializer list>) C++ 中的可调用 class 对象:没有匹配的 function 用于调用 'std::tuple<t> ::元组(<brace-enclosed initializer list> )'</brace-enclosed></t> - Callable class objects in C++ : no matching function for call to ‘std::tuple<T>::tuple(<brace-enclosed initializer list>)’ 用大括号括起来的初始化程序列表 - brace-enclosed initializer list 没有用于调用std :: vector的匹配函数 <std::tuple> 推回 - no matching function for call to std::vector<std::tuple> push_back gcc 不是 clang 上的错误:无法从“转换”<brace-enclosed initializer list> ' 到 'std::vector&lt;&gt;</brace-enclosed> - error on gcc not clang: cannot convert from '<brace-enclosed initializer list>' to 'std::vector<> 错误:没有匹配的 function 调用 'uWS::TemplatedApp<false> ::ws<main()::userdata> (常量字符 [3],<brace-enclosed initializer list> )'</brace-enclosed></main()::userdata></false> - error: no matching function for call to 'uWS::TemplatedApp<false>::ws<main()::UserData>(const char [3], <brace-enclosed initializer list>)'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM