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











up vote
1
down vote

favorite












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:



plot.cpp:12:63: error: converting to ‘std::tuple<std::basic_string<char, 
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >’
from initializer list would use explicit constructor
‘constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...)
[with _UElements = {const char (&)[4], const char (&)[6], const char (&)[6]};
<template-parameter-2-2> = void; _Elements = {std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> >}]’


like 12 of plot.cpp looks like this:



vector<tuple <string, string, string> >{
{"yes", "Agree", "Empty"}, {"no", "Disagree", "Empty"}},


This vector is initialised in header.h, here:



class Menu
{
std::string _name, _situation, _excuse;
std::vector<std::tuple <std::string, std::string, std::string>> _choices;
std::vector<std::string> _items;

public:
Menu(const std::string &name,
const std::string &situation,
const std::string &excuse,
const std::vector<std::tuple <std::string, std::string, std::string>> &choices = std::vector<std::tuple <std::string,std::string, std::string> >{},
const std::vector<std::string> &items = std::vector<std::string>{});
virtual ~Menu ();
const bool operator==(const std::string &name);
const std::string& Explain_Choice();
const void Enter_String();
std::string choice;
std::string ItemChoice;
const void Present_Choice() ;
const void No_Choice();
};


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.










share|improve this question






















  • Please reduce your code to the Minimal, Complete and Verifiable Example that reproduces the problem. It's much easier to help if you can see a toy example that reproduces the error (and the whole error message).
    – Useless
    Nov 20 at 15:03















up vote
1
down vote

favorite












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:



plot.cpp:12:63: error: converting to ‘std::tuple<std::basic_string<char, 
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >’
from initializer list would use explicit constructor
‘constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...)
[with _UElements = {const char (&)[4], const char (&)[6], const char (&)[6]};
<template-parameter-2-2> = void; _Elements = {std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> >}]’


like 12 of plot.cpp looks like this:



vector<tuple <string, string, string> >{
{"yes", "Agree", "Empty"}, {"no", "Disagree", "Empty"}},


This vector is initialised in header.h, here:



class Menu
{
std::string _name, _situation, _excuse;
std::vector<std::tuple <std::string, std::string, std::string>> _choices;
std::vector<std::string> _items;

public:
Menu(const std::string &name,
const std::string &situation,
const std::string &excuse,
const std::vector<std::tuple <std::string, std::string, std::string>> &choices = std::vector<std::tuple <std::string,std::string, std::string> >{},
const std::vector<std::string> &items = std::vector<std::string>{});
virtual ~Menu ();
const bool operator==(const std::string &name);
const std::string& Explain_Choice();
const void Enter_String();
std::string choice;
std::string ItemChoice;
const void Present_Choice() ;
const void No_Choice();
};


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.










share|improve this question






















  • Please reduce your code to the Minimal, Complete and Verifiable Example that reproduces the problem. It's much easier to help if you can see a toy example that reproduces the error (and the whole error message).
    – Useless
    Nov 20 at 15:03













up vote
1
down vote

favorite









up vote
1
down vote

favorite











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:



plot.cpp:12:63: error: converting to ‘std::tuple<std::basic_string<char, 
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >’
from initializer list would use explicit constructor
‘constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...)
[with _UElements = {const char (&)[4], const char (&)[6], const char (&)[6]};
<template-parameter-2-2> = void; _Elements = {std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> >}]’


like 12 of plot.cpp looks like this:



vector<tuple <string, string, string> >{
{"yes", "Agree", "Empty"}, {"no", "Disagree", "Empty"}},


This vector is initialised in header.h, here:



class Menu
{
std::string _name, _situation, _excuse;
std::vector<std::tuple <std::string, std::string, std::string>> _choices;
std::vector<std::string> _items;

public:
Menu(const std::string &name,
const std::string &situation,
const std::string &excuse,
const std::vector<std::tuple <std::string, std::string, std::string>> &choices = std::vector<std::tuple <std::string,std::string, std::string> >{},
const std::vector<std::string> &items = std::vector<std::string>{});
virtual ~Menu ();
const bool operator==(const std::string &name);
const std::string& Explain_Choice();
const void Enter_String();
std::string choice;
std::string ItemChoice;
const void Present_Choice() ;
const void No_Choice();
};


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.










share|improve this question













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:



plot.cpp:12:63: error: converting to ‘std::tuple<std::basic_string<char, 
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >’
from initializer list would use explicit constructor
‘constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...)
[with _UElements = {const char (&)[4], const char (&)[6], const char (&)[6]};
<template-parameter-2-2> = void; _Elements = {std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> >}]’


like 12 of plot.cpp looks like this:



vector<tuple <string, string, string> >{
{"yes", "Agree", "Empty"}, {"no", "Disagree", "Empty"}},


This vector is initialised in header.h, here:



class Menu
{
std::string _name, _situation, _excuse;
std::vector<std::tuple <std::string, std::string, std::string>> _choices;
std::vector<std::string> _items;

public:
Menu(const std::string &name,
const std::string &situation,
const std::string &excuse,
const std::vector<std::tuple <std::string, std::string, std::string>> &choices = std::vector<std::tuple <std::string,std::string, std::string> >{},
const std::vector<std::string> &items = std::vector<std::string>{});
virtual ~Menu ();
const bool operator==(const std::string &name);
const std::string& Explain_Choice();
const void Enter_String();
std::string choice;
std::string ItemChoice;
const void Present_Choice() ;
const void No_Choice();
};


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.







c++ linux macos tuples






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 at 14:41









Andrew

286




286












  • Please reduce your code to the Minimal, Complete and Verifiable Example that reproduces the problem. It's much easier to help if you can see a toy example that reproduces the error (and the whole error message).
    – Useless
    Nov 20 at 15:03


















  • Please reduce your code to the Minimal, Complete and Verifiable Example that reproduces the problem. It's much easier to help if you can see a toy example that reproduces the error (and the whole error message).
    – Useless
    Nov 20 at 15:03
















Please reduce your code to the Minimal, Complete and Verifiable Example that reproduces the problem. It's much easier to help if you can see a toy example that reproduces the error (and the whole error message).
– Useless
Nov 20 at 15:03




Please reduce your code to the Minimal, Complete and Verifiable Example that reproduces the problem. It's much easier to help if you can see a toy example that reproduces the error (and the whole error message).
– Useless
Nov 20 at 15:03












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Something looks fishy here:



         ...
const std::string &excuse,
const std::vector<std::tuple <std::string, std::string, std::string>> &choices = std::vector<std::tuple <std::string,std::string, std::string> >{},
const std::vector<std::string> &items = std::vector<std::string>{});
...


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<...> >.






share|improve this answer























  • thank you very much. I will come back and try solve this problem sometime, but for the moment i upgraded to g++ 8 and its seemed to solve the problem
    – Andrew
    Nov 21 at 19:21











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395452%2fprogram-can-compile-on-mac-but-not-linux-gets-error-converting-to-from-initia%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Something looks fishy here:



         ...
const std::string &excuse,
const std::vector<std::tuple <std::string, std::string, std::string>> &choices = std::vector<std::tuple <std::string,std::string, std::string> >{},
const std::vector<std::string> &items = std::vector<std::string>{});
...


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<...> >.






share|improve this answer























  • thank you very much. I will come back and try solve this problem sometime, but for the moment i upgraded to g++ 8 and its seemed to solve the problem
    – Andrew
    Nov 21 at 19:21















up vote
1
down vote



accepted










Something looks fishy here:



         ...
const std::string &excuse,
const std::vector<std::tuple <std::string, std::string, std::string>> &choices = std::vector<std::tuple <std::string,std::string, std::string> >{},
const std::vector<std::string> &items = std::vector<std::string>{});
...


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<...> >.






share|improve this answer























  • thank you very much. I will come back and try solve this problem sometime, but for the moment i upgraded to g++ 8 and its seemed to solve the problem
    – Andrew
    Nov 21 at 19:21













up vote
1
down vote



accepted







up vote
1
down vote



accepted






Something looks fishy here:



         ...
const std::string &excuse,
const std::vector<std::tuple <std::string, std::string, std::string>> &choices = std::vector<std::tuple <std::string,std::string, std::string> >{},
const std::vector<std::string> &items = std::vector<std::string>{});
...


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<...> >.






share|improve this answer














Something looks fishy here:



         ...
const std::string &excuse,
const std::vector<std::tuple <std::string, std::string, std::string>> &choices = std::vector<std::tuple <std::string,std::string, std::string> >{},
const std::vector<std::string> &items = std::vector<std::string>{});
...


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<...> >.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 at 15:17

























answered Nov 20 at 15:04









Major

1929




1929












  • thank you very much. I will come back and try solve this problem sometime, but for the moment i upgraded to g++ 8 and its seemed to solve the problem
    – Andrew
    Nov 21 at 19:21


















  • thank you very much. I will come back and try solve this problem sometime, but for the moment i upgraded to g++ 8 and its seemed to solve the problem
    – Andrew
    Nov 21 at 19:21
















thank you very much. I will come back and try solve this problem sometime, but for the moment i upgraded to g++ 8 and its seemed to solve the problem
– Andrew
Nov 21 at 19:21




thank you very much. I will come back and try solve this problem sometime, but for the moment i upgraded to g++ 8 and its seemed to solve the problem
– Andrew
Nov 21 at 19:21


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395452%2fprogram-can-compile-on-mac-but-not-linux-gets-error-converting-to-from-initia%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'