0

I am writing some code to wrap some GLFW objects.

I have a private shared_ptr<GLFWwindow> field on my class. GLFW has methods such as glfwDestroyWindow, which I use as glfwDestroyWindow(_windowPtr.get()), since the library is a C library.

I am curious if there is a way to call glfwDestroyWindow whenever the pointer is unassigned (specifically, just before it happens). Can this be done?

  • 3
    Yes, [`std::shared_ptr`](https://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr) allows you to specify a custom deleter function that is called when the pointer is to be destroyed. – G. Sliepen Jun 25 '21 at 21:04
  • 1
    Tactical note: prefer to ask how something can be done. "Can it be done?" can result in yes-or-no answers that are ultimately useless to you. – user4581301 Jun 25 '21 at 21:06

0 Answers0