Point P0(0,0), P1(3, 4), P2(-50,-3), P3(2,0); //Input Points (fine)
std::vector<Point> Points(P0,P1, P2 ,P3); (not fine)
This does not seem to work. How do I initialize points vector to the values above? Or is there an easier way to do this?
Point P0(0,0), P1(3, 4), P2(-50,-3), P3(2,0); //Input Points (fine)
std::vector<Point> Points(P0,P1, P2 ,P3); (not fine)
This does not seem to work. How do I initialize points vector to the values above? Or is there an easier way to do this?
If you are using c++11, you can use braces to declare vectors inline.
std::vector<Point> Points {P0, P1, P2, P3};
Try the following code (not tested):
Point P0(0,0), P1(3, 4), P2(-50,-3), P3(2,0); //Input Points (fine)
std::vector<Point> Points;
Points.push_back(P0);
Points.push_back(P1);
Points.push_back(P2);
Points.push_back(P3);
There is no need to define objects of type Point that to define the vector. You could write
std::vector<Point> Points{ { 0, 0 }, { 3, 4 }, { -50,-3 }, { 2, 0 } };
provided that your compiler supports the brace initialization. Or you could define an array of Point and use it to initialize the vector. For example
#include <vector>
#include <iterator>
//,,,
Point a[] = { Point( 0, 0 ), Point( 3, 4 ), Point( -50,-3 ), Point( 2, 0 ) };
std::vector<Point> Points( std::begin( a ), std::end( a ) ) ;
This code will be compiled by MS VC++ 2010.