Search code examples
c++arraysvolatile

Assigning values to volatile array in c++


I have a volatile array of type MyType mapped to a shared memory, created with CreateFileMapping etc:

volatile MyType *arr;

How do I assign a value to an index of the array? E.g:

MyType a;
arr[n] = a;

I get the compile error:

error C2678: binary '=' : no operator defined which takes a left-hand operand of type 'volatile MyType' (or there is no acceptable conversion)

I would like to be able to both be able to assign MyType to volatile and non-volatile arrays.

Thanks in advance


Solution

  • You did not mark your assignment operator as volatile. Volatile correctness is identical to const correctness- you have a volatile object but no volatile operator, so the call is ill formed.