Jump to content
  • Advertisement
Sign in to follow this  
bory

compiling problems with g++

This topic is 4832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I use the compiler Forte C++ 6.update 2 and when I'm trying to compile something with g++ I receive the errors: include/abl/List.h:151: warning: `class List<void *>' has virtual functions but non-virtual destructor include/MyObject.h:151: warning: `class MyObject' has virtual functions but non-virtual destructor etc.. If I compile the same programm but with CC it compiles succesfull. Do you think it's a compiler problem? What I want to do is to compile my programm as a dynamic library (as a static library I succeded). Thank you for your time.

Share this post


Link to post
Share on other sites
Advertisement
Those are not errors; just warnings. And it's not a compiler problem, you are doing something that is likely to end up causing problems. If a class has virtual functions then you should give it a virtual destructor.

Share this post


Link to post
Share on other sites
Just change ~MyObject(); into virtual ~MyObject(); and you're fine.

Secondly, I couldn't help notice that you're compiling a templated class, called List<void *>.
Is there a reason for using a custom-made class, as opposed to using std::list ?

Share this post


Link to post
Share on other sites
what happens when you provide a virtual distructor for the classes that give you an error like this? (just write virtual infront of the destructor)

Share this post


Link to post
Share on other sites
The error disappears for one. Also derived classes are allowed to override the destructor, allowing them to perform their own destruction tasks (I think I got that right).

BTW, for the most part all compiler errors are generated by the programmer, and not by the compiler. The reason you're getting the warnings is because Visual C++ is a more lenient compiler - a lot of code that compiles on VC will not compile with G++ because G++ is very strict in terms of code correctness. This is very good for your programming habits, of course, but it can take some getting used to ;).

Cheers!

Share this post


Link to post
Share on other sites
If a class has virtual functions, that means that you plan on using it polymorphically. I.e. keep a pointer or reference to the base class around, while the object really is of a derived type. Base* ptr = new Derived;.

The question is, what will happen when you try to destroy that object? delete ptr;. If the destructor isn't virtual, you will not get polymorphic behaviour for that operation, and you will end up calling the wrong destructor, which will definitely cause problems (officially, it has undefined behaviour, meaning "we take no responsibility for what happens if you do it".)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!