Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initializer list of std::pair<vector<int>, double>

Tags:

c++

Hi I am working through some C++ issues and I'm not familiar with the language.

I am trying to initialize a std::pair, double> with this syntax:

 std::pair<std::vector<int>, double> output = { {}, 0.0f };

gcc 5.4.0 on Ubuntu 16.04 generates this error:

no known conversion for argument 1 from ‘std::pair<std::vector<int>, double>’ to ‘std::initializer_list<int>

The same error happens if I use this syntax:

std::pair<std::vector<int>, double> output{{}, 0.0f };

What is the issue?

like image 292
ragnacode Avatar asked Mar 01 '26 03:03

ragnacode


1 Answers

You are using an extended initializer list (std::initializer_list) which is available since C++11.

For the gcc 5.4.0 compiler, you need to compile it with C++11 flag:

$ g++ main.cpp -std=c++11

https://gcc.godbolt.org/z/SHzREE

like image 83
borievka Avatar answered Mar 03 '26 16:03

borievka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!