I read Effective C ++, which tells me that "member functions that differ only in their constant can be overloaded."
Example book:
class TextBlock { public: const char& operator[](std::size_t position) const; char& operator[](std::size_t position); private: std::string text; }
In my example below, the saved pointer is used.
class A { public: A(int* val) : val_(val) {} int* get_message() { return val_; } const int* get_message() { return val_; } const; private: int* val_; };
I get:
error C2556: 'const int * A :: get_message (void)': the overloaded function differs only in the return type from 'int * A :: get_message (void)'
What is the difference? Is there a way I can fix the class, so I have a constant and non-constant version of get_message?
source share