All pastes #1672778 Raw Edit

Cast away const in a member func

public cpp v1 · immutable
#1672778 ·published 2009-11-16 00:03 UTC
rendered paste body
edulix@edulix-laptop:~/descargas$ cat main.cpp#include <iostream>using namespace std;struct A {        void bar()        {                cout << "hello" << endl;        }        void foo() const        {                void (A::*ptr)() = reinterpret_cast<void (A::*)()>(&A::bar);                A* this_unconst = const_cast<A*>(this);                (this_unconst->*ptr)();        }};int main() {        A a;        a.foo();        return 0;}edulix@edulix-laptop:~/descargas$ make maing++     main.cpp   -o mainedulix@edulix-laptop:~/descargas$ ./mainhelloedulix@edulix-laptop:~/descargas$