Registered Member
|
The following code works:
why?? |
Moderator
|
Calling placement new does not change the type of the object, and since mUseless is not a const Map, it is perfectly normal that you can change the object. Your code is similar to a reinterpret_cast from a Map<const Matrix<double,3,3> > to a Map<Matrix<double,3,3> >.
|
Registered Member
|
So how may I protect a Map from writing?? I'm using the same map for several operatation with raw buffers. Some of
those buffers are const. It is mandatory to use specially a new Map<const Type > to work with const arrays? or there is another way to implement a single map to work with both const and not const in a secure way?? And there is not a way to forbid the "new (&,mUseless) Map<const Matrix<double,3,3> >" statements when mUseless is not a map to const?? |
Moderator
|
You can use const map even to map non const pointers:
Map<const Matrix<double,3,3> > mUseless(ptr1); In which case mUseless(1,1)= blabla; will be forbidden regardless of the constness of the input pointer. But in C++ an object cannot change its constness at runtime! |
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]