开发者

no suitable constructor exists to convert from "uint8_t *" to "std::vector<uint8_t, std::allocator<uint8_t>>"

开发者 https://www.devze.com 2023-02-13 13:58 出处:网络
no suitable constructor exists to convert from \"uint8_t *\" to \"std::vector<uint8_t, std::allocator<uint8_t>>\"
no suitable constructor exists to convert from "uint8_t *" to "std::vector<uint8_t, std::allocator<uint8_t>>"

and the cast not working

Edit:

const std::vector<开发者_如何学C;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>>"


You cannot convert an array to a std::vector, you need to construct one explicitly. One way to do it would be to use the vector's range constructor like this:

uint8_t* buffer="...";
// +1 for the terminating \0
std::vector<uint8_t> vector( buffer, buffer + strlen( buffer ) + 1 ); 
Test( vector );

As a side note if your buffer has embedded \0 then strlen will return an incorrect value. As a workaround you can do something like this:

uint8_t[] buffer="...";
std::vector<uint8_t> vector( buffer, buffer + sizeof( buffer ) ); 
Test( vector );
0

精彩评论

暂无评论...
验证码 换一张
取 消