Answers for "how to have const and not const version in C++"

1

Elegant solution to duplicate, const and non-const, getters?

class Foo
{
public:
    const int& get() const
    {
        //non-trivial work
        return foo;
    }

    int& get()
    {
        return const_cast<int&>(const_cast<const Foo*>(this)->get());
    }
};
Posted by: Guest on August-23-2020

Browse Popular Code Answers by Language