Skip to content
Advertisement

Program can compile on Mac, but not Linux. Gets error: converting to from initializer list

I have a program which will successfully compile on my mac but when I try on my linux desktop it cannot. Instead, I get the following error:

JavaScript

like 12 of plot.cpp looks like this:

JavaScript

This vector is initialised in header.h, here:

JavaScript

I have looked around a bit and I suspect the error is coming from the line in header.h where I say &choices =. However, my attempts to initialise this differently have not worked.

I have 2 questions. Firstly, why can this code compile on my mac but not on linux, is one of the compilers somehow ”wrong”? And then secondly, is there any suggestions on how I can change my code to allow it to compile on the Linux machine.

Advertisement

Answer

Something looks fishy here:

JavaScript

I know you can pass by reference with a default const parameter, but this definitely looks like code smell.

Based on the error message, it looks like this second line is where your error is coming from. It may be better in this case to overload the constructor instead of having these specific default arguments.

This answer has more information about this specific error (unordered_map, but the rational and explanation is the same).

In summary, this could be be a difference between default C++ standards the compilers are using. g++ uses std=c++11 by default, not sure what the OSX compiler uses. You may need to pass in std=c++14 to g++ to get the smarter default constructors for the std::vector<std::tuple<...> >.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement