3

How to Declare byte* ( byte array ) in c++ and how to define as a parameter in function definition?

when I declare like below

Function Declaration:

int Analysis(byte* InputImage,int nHeight,int nWidth);

Getting error : "byte" undefined

7
  • use unsigned char instead. its the same....one byte Commented Apr 18, 2013 at 9:49
  • then how should i convert byte* in to unsigned char, getting byte array input from the C# application. Commented Apr 18, 2013 at 9:53
  • Did you want to convert byte from c# to char in c++? am i understand this correctly? Commented Apr 18, 2013 at 10:02
  • 1
    I think you can do this by convert byte into char in c# before pass on to c++ char Commented Apr 18, 2013 at 10:03
  • This one should help you in converting byte in c# to char stackoverflow.com/questions/5431004/… Commented Apr 18, 2013 at 10:04

2 Answers 2

6

There is no type byte in C++. You should use typedef before. Something like

typedef std::uint8_t byte;

in C++11, or

typedef unsigned char byte;

in C++03.

Sign up to request clarification or add additional context in comments.

Comments

5

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).

However, in modern C++, you shouldn't be using raw arrays. 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. You can pass these to functions via (const) references, like this:

int Analysis(std::vector<unsigned char> &InputImage, int nHeight, int nWidth);

If Analysis does not modify the array or its elements, do this instead:

int Analysis(const std::vector<unsigned char> &InputImage, int nHeight, int nWidth);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.