[英]How to Declare byte* ( byte array ) in c++?
How to Declare byte* ( byte array ) in c++ and how to define as a parameter in function definition? 如何在C ++中声明byte *(字节数组),以及如何在函数定义中定义为参数?
when I declare like below 当我声明如下
Function Declaration: 功能声明:
int Analysis(byte* InputImage,int nHeight,int nWidth);
Getting error : "byte" undefined 正在获取错误:“字节”未定义
There is no type byte
in C++. C ++中没有类型
byte
。 You should use typedef
before. 您应该在之前使用
typedef
。 Something like 就像是
typedef std::uint8_t byte;
in C++11, or 在C ++ 11中,或
typedef unsigned char byte;
in C++03. 在C ++ 03中。
The C++ type representing a byte is unsigned char
(or other sign flavour of char
, but if you want it as plain bytes, unsigned
is probably what you're after). 代表一个字节的C ++类型是
unsigned char
(或其他标志味char
,但如果你想把它当作普通的字节, unsigned
可能是你以后在做什么)。
However, in modern C++, you shouldn't be using raw arrays. 但是,在现代C ++中,您不应该使用原始数组。 Use
std::vector<unsigned char>
if your array is runtime-size, or std::array<unsigned char, N>
(C++11) if your array is of static size N
. 如果数组为运行时大小,则使用
std::vector<unsigned char>
如果数组的静态大小为N
,则使用std::array<unsigned char, N>
(C ++ 11)。 You can pass these to functions via (const) references, like this: 您可以通过(const)引用将它们传递给函数,如下所示:
int Analysis(std::vector<unsigned char> &InputImage, int nHeight, int nWidth);
If Analysis
does not modify the array or its elements, do this instead: 如果
Analysis
没有修改数组或其元素,请执行以下操作:
int Analysis(const std::vector<unsigned char> &InputImage, int nHeight, int nWidth);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.