I try to declare the following class in C++; however, I have gotten the following error. Is there something wrong with pointers?
class classFather{
public:
int BmcCommand;
int BmcDataLength;
byte BmcDataBuffer[];
classFather() {
BmcCommand = 0;
BmcDataLength = 0;
BmcDataBuffer = new byte[CMD_LENGTHH];
}
classFather(byte s8Command, int siLength, byte as8Data[]) {
BmcCommand = s8Command;
BmcDataLength = siLength;
int size = sizeof( as8Data ) / sizeof( as8Data[0] );
BmcDataBuffer = new byte[size];
for(int ii=0; ii< size; ii++)
BmcDataBuffer[ii] = as8Data[ii];
}
private:
static const short CMD_LENGTHH = 255;
};
I’m getting the following error:
error: incompatible types in assignment of `byte*' to `byte[0u]'
C:\....\BluetoothClient\/msgCAN.h: In constructor `msgCANFather::msgCANFather(byte, int, byte*)':
As others said, you try to assign a pointer to an array.
Better then writing memory leaks this way (I see a
newbut nodelete), use avector:Note:
Will always return
sizeof( byte* ) / sizeof( byte* ), i.e. 1.Note 2: you could use an initializer list to create the
vectormember in one go:the
vectorconstructor will copy allasDataelements.