-3

I am getting a warning:

error: deleting object of abstract class type ‘Converter::ConversionImpl’ which has non-virtual destructor will cause undefined behavior [-Werror=delete-non-virtual-dtor]
     delete it->second;
                ^~~~~~

That is causing me a few difficulties in solving. I've tried applying virtual, but I suspect this has something more to do with the map, which is a multimap and I can't seem to find an alternative to the virtual delete operator. In fact all my research suggests that this is in fact the right way to do it, if a little non-standard. (None of the research examples were a match for what is actually being done here).

typedef multimap<int,ConversionImpl*> ConversionImplList;

struct CRegistry {
    ConversionImplList list;
    CRegistry();

    ~CRegistry()
    {
        for (ConversionImplList::iterator it=list.begin(); it!=list.end(); ++it)
        {
            delete it->second;
        }

        list.clear();
    }
};

Why is it throwing up the issue with second and not with the destructor as a whole and where would be the best place to find materials that would cover this scenario?

Code in Full (Not the best work in the world I agree, I'm still getting my head around everything). Converter.h

Edit

The solution to this one is indicated in a comment below and refers to a class declared in an associated header not in the file itself. The key here is to look at the wording of the warning message carefully because the words mean specific things.

In this case the class up one, failed to declare the destructor to be "virtual". In all likelihood, when a similar error comes up this is likely to be the cause.

Myut
  • 5
  • 1
  • 6
  • error message means the `ConversionImpl` class needs a virtual destructor. Might be able to tell you more, but... The broken link to your code is only one of many reasons we like to have all necessary information in the question and not dangling off the side somewhere. Best place to get more information is [probably a good book.](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – user4581301 Mar 05 '17 at 04:26
  • 1
    @user4581301, thanks for the response, I'll try that. Edit: Tried that, that was indeed the solution. Thank you very much I'll credit your answer in my next commit. – Myut Mar 05 '17 at 05:12
  • Why do you have pure virtual functions in your `Converter:: ConversionImpl` class? – ThomasMcLeod Mar 05 '17 at 16:04
  • My class? Heh. The code here was originally authored by someone else and submitted to the Vega Strike project. I believe it has virtual functions because the class is inherited elsewhere. – Myut Mar 06 '17 at 16:20

1 Answers1

0

I cannot find any place in your code where pointers are added to list. However, you cannot instantiate a class with pure virtual functions as the full type, such s Converter::ConversionImpl. Hence the elements in your list cannot point to objects of polymorphic type Converter::ConversionImpl. You must inherit from this class before you can use it.

Either add an implementation to the pure virtual functions or derive from the class and make the destructor virtual as well. In that case you will need to override the virtual functions in the base class.

ThomasMcLeod
  • 7,603
  • 4
  • 42
  • 80
  • Honestly speaking, neither can I. The "Converter" is (I think) supposed to convert .obj and .mbt(?) into a format called .BXMF and/or .XMESH ...and makes extensive use of macros to do anything. With that said, ConversionImpl needed a virtual destructor, so it got one. Never the less it was @user4581301 's solution that worked. – Myut Mar 06 '17 at 16:18