Welcome to %s forums

BrainModular Users Forum

Login Register

arrays/vectors stuff question

Create your own modules in C++
Post Reply
23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 25 Apr 2015, 23:32

I first build all my module using arrays. oming from the delphi it didn't take time to understand that wasn't exactly as easy with cpp relating dynamics sizes.
then i tought i understood the use of 'new' command, and globally all worked as espected.

but then i had/have a bit more complex stuff to do like insert some variable lengths and datas , shift ,reorder, inc/dec ect the arrays.
it quicly became imo a nightmare to handle, so i think i was not looking in good dir and tried vectors instead of arrays.
seems to be much more appropiate but i really fail on that one;

what i did, is creating a TPointF vector in header file: (PXY) represents an array of points with XY coords.
[c]
#include <vector>
using namespace std;

vector<TPointF> PXY;
[/c]

i have a private class variable Psize i set to 4 on init , adjust the vector size then whenever its is resized in the code calling this:

PXY.resize(Psize); // maybe i should just allocate confortable room and don't worry?

--kk evertyhing ok for now. then i do some insert/ puch back stuff and so on pocedures ie like:
[c]
if ((Psize + 3) < Psize_Max)
{
vector<TPointF>::iterator IT = PXY.begin();
PXY.reserve(32);
int ID_AT = FIND_NEXT_MAIN(X, Y); // function that returns me an int ID of the next main point

TPointF * PXY3 = new TPointF[3]; //creating an array of points i wanna insert
PXY3[0].x = X - Test_Radius*1.5;
PXY3[0].y = Y;
PXY3[1].x = X;
PXY3[1].y = Y;
PXY3[2].x = X + Test_Radius*1.5;
PXY3[2].y = Y;

for (int i = 0; i < 3; i++) //inserting the points
{
PXY.insert(IT + ID_AT - 1 + i, PXY3);
}
// then here is the problem, i could just make : Psize = Psize+3 but i dlike to understand why this don't work:

---------------> Psize = (int)PXY.size;

[/c]
it returns me this error:
Erreur 54 error C2440: 'cast de type' : impossible de convertir de 'unsigned __int64 (__cdecl std::vector<TPointF,std::allocator<_Ty>>::* )(void) throw() const' en 'int' E:USINE PATCHSensomusic SDK 6.04.002examplesBEZIER_MAPPERBEZIER_MAPPER.cpp 1246 1 BEZIER_MAPPER


what im doing wrong/miss, anybody knows what's the easiest way to get a Vector size as an integer? seems basic but i struggle :(

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Unread post by martignasse » 27 Apr 2015, 10:30

mmm,

i think you should call PXY.reserve(32); before allocating your iterator vector<TPointF>::iterator IT = PXY.begin();
because reserve invalidate the iterator.

see here, Iterator validity section near the bottom of the page
Martin FLEURENT - Usine Developer - SDK maintainer

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 27 Apr 2015, 10:47

aaahh cool gonna try thx martin!! :)

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests