0



Update: This question was answered by Igor in the comments. Turns out I missed the const in my copy-constructor.



I am writing a class that can be stored in an unordered_map, and everything appears to be syntactically correct. When I compile however, the compiler returns some strange errors that seem to have something to do with __is_direct_constructible_new. The error also suggested to try compiling as -ftemplate-backtrace-limit=0, but this caused another error so I'd rather not mess with the compiler flags and instead find the source of the problem.

That being said, my question is: What should I add to make my class "direct constructible"?

I'm including a generalized sample of the class below.

I tried following some of the relevant-sounding suggestions in this post, but those didn't help.

I also made sure that the issue was not being caused by the key or the key's hash.

I've never ran into this before so I'm not sure exactly sure how to make the class direct constructible.

Here is a generalized version of the class I'm referring to:

class Data
{
    public:
        // variables
        // pointers
        // member functions

        Data();                     // Sets variables to 0 and pointers to NULL
        Data(ifstream& dataFile);   // Initializes from a file
        Data(Data& original);       // Copy constructor
        ~Data();
};

If it makes a difference, I tried compiling on both MinGW 32bit and a 64bit version of MinGW 4.8.3 from here.

Community
  • 1
  • 1
Vladimir
  • 225
  • 1
  • 11
  • 4
    See if the outcome changes when you make copy constructor take const reference, as in `Data(const Data& original);` The way you have it is highly unusual, it seems unlikely that you deliberately want it this way. – Igor Tandetnik Aug 22 '14 at 19:02
  • Show us the error message. – David G Aug 22 '14 at 19:03
  • 2
    Also, you have a user-defined copy constructor, but not a user-defined copy-assignment operator. Chances are high you need both, or neither. – Igor Tandetnik Aug 22 '14 at 19:04
  • 1
    @IgorTandetnik Brilliant!!! Please post that as an answer and I'll mark it as correct! :) Thanks very much. I've been stuck of this for several days hahaha – Vladimir Aug 22 '14 at 19:05
  • @IgorTandetnik Hmm that's also a good idea! I'll make the operator too. – Vladimir Aug 22 '14 at 19:07
  • Should this be closed as a dupe (e.g., of http://stackoverflow.com/q/1602058/179910)? – Jerry Coffin Aug 22 '14 at 20:05
  • @JerryCoffin I was waiting for Igor to post his response as an answer so I can mark it as correct in case other people run into a similar issue at some point in the future. The other post doesn't talk about being direct constructible. – Vladimir Aug 22 '14 at 20:22
  • 1
    @Vladimir: if it's closed as a dupe, it remains in the system so people can still find it (but it would also add a link to the question it duplicates, which may provide still more help). – Jerry Coffin Aug 22 '14 at 20:24
  • @JerryCoffin Ok cool :) – Vladimir Aug 22 '14 at 20:50

0 Answers0