1

The problem seems to be with int m = std::max({die1, die2, die3}); it brings up an error in eclipse, but runs fine in Xcode. Why is that? code is

#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
    int die1; 
    int die2; 
    int die3; 
    cin >> die1;
    cin >> die2;
    cin >> die3;
    int m = std::max({die1, die2, die3}); 
    cout << m << endl; 
return 0;
}

the error is

../src/playground.cpp:19:22: error: expected expression
int m = std::max({die1, die2, die3});
                          ^
1 error generated.
make: *** [src/playground.o] Error 1

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 2
    Please [edit] your question to include a [mcve], otherwise we're simply guessing what `die1` etc is and what you've included. Also ensure you include what error you're receiving from eclipse. Is it a compiler error or runtime? – Tas Mar 27 '19 at 21:30
  • 1
    @Tas I added the error, along with the code. – firenation1254 Mar 27 '19 at 21:43

1 Answers1

2

I can think of a couple of reasons for this. Firstly, you should include <algorithm> for std::max, and secondly the initializer list overload was only added in C++11, so it may be that your Eclipse is not compiling in at least C++11.

Tas
  • 7,023
  • 3
  • 36
  • 51
  • I added #include but threw up the same error. If you don't mind me asking how would I check if it is compiling in C++11? And would that mean Xcode is compiling in C++11 because the code runs fine in Xcode, and its running without #include. – firenation1254 Mar 27 '19 at 22:00
  • Yep, XCode is likely compiling in at least C++11. I've not much experience with Eclipse but it would appear [this](https://stackoverflow.com/questions/9131763/how-to-enable-c11-c0x-support-in-eclipse-cdt) should aid you in setting up C++11. – Tas Mar 27 '19 at 22:01