39 57 C:\Users\22269\Documents\Untitled1.cpp [Error] could not convert '{1, 8, 6, 2, 5,…
- User
39 57 C:\Users\22269\Documents\Untitled1.cpp [Error] could not convert '{1, 8, 6, 2, 5, 4, 8, 3, 7}' from '' to 'std::vector'
- Assistant
This error message is telling you that you are trying to initialize a vector with a brace-enclosed initializer list, but the vector cannot be initialized in this way.
To fix this error, you should use the constructor of the vector class to initialize it with the elements you want to store, like this:
std::vector<int> myVector{1, 8, 6, 2, 5, 4, 8, 3, 7};Or, you can initialize an empty vector and then use the
std::vector::push_backmethod to add elements one by one, like this:std::vector<int> myVector; myVector.push_back(1); myVector.push_back(8); myVector.push_back(6); // and so on...Either way, you should be able to initialize and use your vector without any errors.
- User
std::vector<Data*> height;是什么意思
- Assistant
std::vector<Data*>is a declaration of a vector that stores pointers to objects of theDataclass.Here,
std::vectoris a container type that provides dynamic array functionality, which means you can add or remove elements from the vector during runtime.Data*indicates that the type of elements stored in the vector is a pointer to an object of theDataclass.So,
std::vector<Data*> height;defines a vector namedheightthat can store pointers toDataobjects. You can then use the vector to dynamically allocate memory forDataobjects and store their pointers, allowing you to access and manipulate the objects later.