I have an object that at the most basic level looks like this:
#include <X11/Xlib.h> class x_link { public: x_link() { display_ = XOpenDisplay(NULL); } ~x_link() { XCloseDisplay(display_); } Display* display_ptr() const { return display_; } private: Display* display_; };
I was wondering how "const" x_link::display_ptr() should be in that case.
this old question if member functions are "const" if they affect a boolean state but not a bitwise state? , it seems that since my method does not work, t (itself) affects the logical or bitwise state of the object, const is the way to go.
but at the same time, providing Display* allows users to tear an object (for example, by calling XCloseDisplay() themselves), which would be very inconvenient.
any thoughts?
source share