编译OpenCV.sln工程中出现C2440: 无法从“initializer list”转换为“std::vector的错误

使用openCV.sln自动生成过程中遇到的问题,两个错误发生在同一个项目opencv_test_cudaarithm里。

CUDA_TEST_P(AsyncEvent, Timing)
{
    const std::vector<cv::cuda::Event::CreateFlags> eventFlags
        = {cv::cuda::Event::CreateFlags::BLOCKING_SYNC, cv::cuda::Event::CreateFlags::BLOCKING_SYNC | Event::CreateFlags::DISABLE_TIMING};
    const std::vector<bool> shouldFail = { false, true };

关于vector的定义是这样的

template<class _Ty,
    class _Alloc = allocator<_Ty>>
    class vector
        : public _Vector_alloc<_Vec_base_types<_Ty, _Alloc>>
运行结果及报错内容

错误 C2440 “初始化”: 无法从“initializer list”转换为“std::vector<cv::cuda::Event::CreateFlags,std::allocator<_Ty>>” opencv_test_cudaarithm

错误(活动) E0289 没有与参数列表匹配的构造函数 "std::vector<_Ty, _Alloc>::vector [其中 _Ty=cv::cuda::Event::CreateFlags, _Alloc=std::allocatorcv::cuda::Event::CreateFlags]" 实例 opencv_test_cudaarithm

该如何解决这个问题呢?

看你的编译器是否支持c++11

你cmake的时候选的msvc版本是多少?要跟你用vs编译的版本对上
cmake日志输出报错解决了没有?要全部解决好才能编译