It does even compile and I am able to attribute a variable to it. However I am having issue on getting the described behaviour of time formatting out of it. I believe my problem is that Gtk::Entry::set_buffer expects a shared pointer of Gtk::EntryBuffer type, however as it does it, it ignores the overloading of the default handler for inserted text
I’d recommend making a ::create() method, and then whatever object you’ve composed this EntryBuffer into should have a member variable holding the refptr, rather than using the xxx_from_this approach.
–
As for your on_inserted_text method, I’m not sure that chars[position] is valid; the size of chars is n_chars. I think position is not related to chars at all, so using it as an index seems wrong.
No, I wouldn’t derive a Gtk::Entry just to take your TimeBuffer. As the documentation for Glib::RefPtr points out, if you have a Glib::RefPtr<Derived> you can std::dynamic_pointer_cast<Base>, e.g. entry->set_buffer(std::dynamic_pointer_cast<Gtk::EntryBuffer>(ptr_timeBuffer))
In this case I would std::static_pointer_cast, but maybe while you are exploring polymorphism it might be more helpful to use the dynamic error checking version