Force external function to be const

Posted by vanna on Stack Overflow See other posts from Stack Overflow or by vanna
Published on 2012-05-31T10:28:10Z Indexed on 2012/05/31 10:40 UTC
Read the original article Hit count: 261

Here is my problem. I made a class with a member function declared as const that uses an external function that I cannot modify (declared in someone else's code) and that is not declared const. More precisely

Someone else's code

class B {
public:
    void foo();
};

My code

class A : public B {
public:
    void bar() const {
        this->foo();
    }
};

I know that for member data we can force const-correctness by using mutable or const_cast. How can I 'hack' foo such that my compiler understands that I would like to use it as if it was const even if it is not declared in someone else's code ?

© Stack Overflow or respective owner

Related posts about c++

Related posts about const