[英]How to Declare byte* ( byte array ) in c++?
如何在C ++中聲明byte *(字節數組),以及如何在函數定義中定義為參數?
當我聲明如下
功能聲明:
int Analysis(byte* InputImage,int nHeight,int nWidth);
正在獲取錯誤:“字節”未定義
C ++中沒有類型byte
。 您應該在之前使用typedef
。 就像是
typedef std::uint8_t byte;
在C ++ 11中,或
typedef unsigned char byte;
在C ++ 03中。
代表一個字節的C ++類型是unsigned char
(或其他標志味char
,但如果你想把它當作普通的字節, unsigned
可能是你以后在做什么)。
但是,在現代C ++中,您不應該使用原始數組。 如果數組為運行時大小,則使用std::vector<unsigned char>
如果數組的靜態大小為N
,則使用std::array<unsigned char, N>
(C ++ 11)。 您可以通過(const)引用將它們傳遞給函數,如下所示:
int Analysis(std::vector<unsigned char> &InputImage, int nHeight, int nWidth);
如果Analysis
沒有修改數組或其元素,請執行以下操作:
int Analysis(const std::vector<unsigned char> &InputImage, int nHeight, int nWidth);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.