How to compile this vector?
I'm trying to create an inventory and need this kind of vector:
1 2 3 4 5 6 7 8 9 10
|
#include <iostream>
#include <vector>
using namespace std;
int main()
{
// FOOD ITEM ID VALUE WEIGHT
vector<double> Bread {9001, 0.4, 0.5};
}
|
But when I compile i get error:
warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x
error: in C++98 'Bread' must be initialized by constructor, not by '{...}'
error: no matching function for call to 'std::vector<double, std::allocator<double> >::vector(<brace-enclosed initializer list>)'
|
In the book I've got its said "You can do following:
vector<double> N{1,2,3,4,5}
Thanks in advance
EDIT:
I've got GNU GCC Compiler
Last edited on
Wrong type of brackets. Replace the braces ({...}) with parenthesis ((...)).
Last edited on
Solved my own problem by going in to the Global compiler settings and set flag
| Have g++ follow the coming C++0x ISO C++ language standard [-std=c++0x] |
Thanks
Is it not possible to create a class containing the vectors?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include <iostream>
#include <vector>
using namespace std;
class Inventory
{
private:
// FOOD
vector<double> Bread {9001, 0.4, 0.5};
public:
};
int main()
{
}
|
get error:
| 10|error: function definition does not declare parameters |
Last edited on
Your version of GCC is too old to be able to do that. Initialize Bread in the constructor or upgrade your compiler.
Topic archived. No new replies allowed.