Home » Community » Newbie corner » stl question
Re: stl question [message #32797 is a reply to message #32796] |
Fri, 10 June 2011 07:55   |
|
Hi GaroRobe,
You don't have to use new at all Just creating a temporary object is fine, since std::vector will make a copy:
vector<Point2f> checkboardMesh;
for ( int i = 0; i < board_h; i++ )
for ( int j = 0; j < board_w; j++ )
checkboardMesh.push_back ( Point2f ( j, i ) );
Using U++ containers should be possible, but it would be an ugly hack Something allong the lines of: using std::vector;
using cv::Point2f;
Vector<Point2f> v; //this requires to do NAMESPACE_UPP; NTL_MOVEABLE(cv::Point2f); END_UPP_NAMESPACE; in global scope
vector<Point2f> checkboardMesh;
for ( int i = 0; i < board_h; i++ )
for ( int j = 0; j < board_w; j++ )
v.Add( Point2f ( j, i ) );
checkboardMesh.resize(v.GetCount());
memmove(&checkboardMesh[0],v.Begin(),v.GetCount()*sizeof(Point2f)); In other words: not elegant and definitelly not recomended. Please never do something like that 
Honza
|
|
|
Goto Forum:
Current Time: Tue Jul 08 06:30:47 CEST 2025
Total time taken to generate the page: 0.04335 seconds
|