I have a wrapper data structure that I'd like to write a method for the copy assignment operator. I'd really like to do this (because my byte_array
can do some really cool stuff):
byte_array bytes = {0x00, 0xAB, 0xEE, 0xFF};
and the function I'm trying to write looks like this so far:
template <int N>
byte_array& byte_array::operator = (const unsigned char (&a)[N]) {
if(N <= capacity) { //capacity is a class field
for(int i = 0; i < N; i++) array[i] = a[i]; //array is a class field
usage = N; //usage is a class field
}
return *this;
}
However, this code doesn't compile, as it does not like that I gave it a list. It doesn't like a lot of things about this.
Is there something wrong with the function I wrote, such as the assignment operator only working on objects of the same type (like a conflict of byte_array
and unsigned char[]
)? Is it an issue of my 'list' that I'm trying to assign it to not matching up with the unsigned char[]
type?
I was basing my function off of an answer to this past question about arrays in C++.