no suitable constructor exists to convert from "uint8_t *" to "std::vector<uint8_t, std::allocator<uint8_t>>"
并且演员无效
编辑:
const std::vector<uint8_t> Test (const std::vector<uint8_t> buffer) const;
uint8_t* buffer="...";
//so i can use Test() function
Test(buffer);
Error
no suitable constructor exists to convert from "uint8_t *" to "std::vector<uint8_t, std::allocator<uint8_t>>"
答案 0 :(得分:4)
您无法将array
转换为std::vector
,您需要明确构建一个。
一种方法是使用vector
的范围构造函数,如下所示:
uint8_t* buffer="...";
// +1 for the terminating \0
std::vector<uint8_t> vector( buffer, buffer + strlen( buffer ) + 1 );
Test( vector );
如果您的缓冲区已嵌入\0
,那么strlen
将返回不正确的值。作为一种解决方法,您可以执行以下操作:
uint8_t[] buffer="...";
std::vector<uint8_t> vector( buffer, buffer + sizeof( buffer ) );
Test( vector );