Please have a look at the followng header file
#pragma once
class MissileLauncher
{
public:
MissileLauncher(void);
private:
byte abc[3];
};
This generated the error
Error 1 error C2143: syntax error : missing ';' before '*'
I tried to do it in this way
byte *abc;
but it also failed, same error. However, I noticed I can call other built in tyes arrays in this way for an example, an int array. Why this is happening to byte array? How to solve this? I would like to assign the values in cpp file. Any ideas?
byte array in CAn unsigned char can contain a value from 0 to 255, which is the value of a byte. In this example, we are declaring 3 arrays – arr1, arr2, and arr3, arr1 is initialising with decimal elements, arr2 is initialising with octal numbers and arr3 is initialising with hexadecimal numbers.
A byte is typically 8 bits. C character data type requires one byte of storage. A file is a sequence of bytes. A size of the file is the number of bytes within the file. Although all files are a sequence of bytes,m files can be regarded as text files or binary files.
In the byte stream model, a file is just a stream of bytes, with no record boundaries. Newline characters written to the stream appear in the external file. If the file is opened in binary mode, any newline characters previously written to the file are visible on input.
If we want to determine the size of array, means how many elements present in the array, we have to write calculation with the help of sizeof() operator. Sizeof(arr[]) / sizeof(arr[0]) ; Here, the size of arr[] is 5 and each float takes memory 8 bytes. So, the total memory is consumed = (5 * 8) bytes.
Try
class MissileLauncher
{
public:
MissileLauncher(void);
private:
unsigned char abc[3];
};
or
using byte = unsigned char;
class MissileLauncher
{
public:
MissileLauncher(void);
private:
byte abc[3];
};
**Note: In older compilers (non-C++11) replace the using
line with typedef unsigned char byte;
If you want exactly one byte, uint8_t defined in cstdint would be the most expressive.
http://www.cplusplus.com/reference/cstdint/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With