簡體   English   中英

沒有合適的構造函數來將“ uint8_t *”轉換為“ std :: vector” <uint8_t, std::allocator<uint8_t> &gt;”

[英]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>>"

和演員不起作用

編輯:

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>>"

您不能將array轉換為std::vector ,您需要顯式構造一個array 一種方法是使用vector的range構造函數,如下所示:

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

附帶說明一下,如果您的緩沖區已嵌入\\0strlen將返回錯誤的值。 作為解決方法,您可以執行以下操作:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM