Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tgui::Gui has virtual methods but no virtual destructor #12

Closed
Wizzard033 opened this issue Aug 24, 2013 · 7 comments
Closed

Tgui::Gui has virtual methods but no virtual destructor #12

Wizzard033 opened this issue Aug 24, 2013 · 7 comments

Comments

@Wizzard033
Copy link

warning: deleting object of polymorphic class type 'tgui::Gui' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]

This occurs when using dynamic allocation via operator new and operator delete for tgui::Gui instances.

@texus
Copy link
Owner

texus commented Aug 24, 2013

But is it really needed to implement a virtual destructor? It is only needed when you are using a pointer to a derived class. And Gui isn't intended to be used as base class, neither should u use new and delete.

@Wizzard033
Copy link
Author

The usage of new and delete with tgui::Gui in my circumstance comes from binding TGUI to a scripting language.
As I am not using C++ when I create and delete instances, using C++ scoping rules is out of the question.

@Wizzard033
Copy link
Author

I suppose instead of using new/delete I could create a global container of GUI instances...
This is a nuisance though. My previous code worked and only broke as a result of updating TGUI.
The scripting language I use, Squirrel, was already made for plugging in new/delete or malloc/free in this scenario.
Doing anything different would be a hack...

Edit: Extra, unnecessary copying would be involved too in making the global container hack...

@texus
Copy link
Owner

texus commented Aug 24, 2013

Using new/delete is ok then in your situation, and you should be able to safely ignore this warning.
I'll either implement an empty virtual destructor, or mark the class as final. But I'll see about that later.

@Wizzard033
Copy link
Author

Removing the virtual keyword from all members that have it is an option too...

@texus
Copy link
Owner

texus commented Aug 24, 2013

I'll look into this later. I'm currently writing something for LD, so I don't want to spend too much time on my gui right now.
And because it is just a warning I think it can be ignored for a few days.

@Wizzard033
Copy link
Author

No problem
Thank you for the nearly immediate responses.

texus added a commit that referenced this issue Aug 25, 2013
@texus texus closed this as completed Aug 25, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants