Original Post
Hey this is a compile error (VS2005) that I had never encountered before:
class Test
{
public:
void f() {};
};
volatile Test *p = new Test;
const_cast<Test*>(p)->f(); // OK
p->f(); // cannot convert 'this' pointer from 'volatile Test' to 'Test &'
That would make sense in the case I had called a non const member on a const member, in which case I'd just fix my design, but here... Even if there was a way to force the implicit "this" to be considered a "volatile Test*", I could want to call the member function on non volatile pointers as well. What do you say? Is there any better way to fix this, or is that a legitimate use of const_cast?