I have a template class like this:
template<T>
class MyClass
{
T* data;
}
Sometimes, I want to use the class with a constant type T as follows:
MyClass<const MyObject> mci;
but I want to modify the data using const_cast<MyObject*>data
(it is not important why but MyClass
is a reference count smart pointer class which keeps the reference count in the data itself. MyObject
is derived from some type which contains the count.
The data should not be modified but the count must be modified by the smart pointer.).
Is there a way to remove const-ness from T
? Fictional code:
const_cast<unconst T>(data)
?