If I have this function:
void initPoints(sf::Vector2f points[]);
Why can I do this:
sf::Vector2f[] vecs = {sf::Vector2f(0,0), etc};
initPoints(vecs);
But can't do this?
initPoints({sf::Vector2f(0,0), etc});
VS gives me an error on the second one, but not on the first one.
By using std::vector
or std::array
you can resolve your problem easier :) Furthermore, std::vector
is RAII-conform, so you don't have to manage the memory by yourself. Generally, STL classes are better than C-type arrays.
#include <vector>
#include <initializer_list>
// ...
std::vector<sf::Vector2f> vecs = { Vector2f(0,0), etc };
Then:
initPoints(const std::vector<sf::Vector2f>& vec) {
// ...
}
initPoints(vecs);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments