I'm making a function that takes four integers(line coordinates) then returns a pointer to a vector of pairs(pixel coordinates), I'm having trouble allocating the vector and initializing the pairs to zero.
the compiler is not accepting an expression in vector allocation: expected a type, got '(X1 - Xo)'
If someone could explain to me how new
works, does it create actually the vector & there are pairs object in it uninitialized , or does it just reserve the mentioned object's size?
my function code is:
vector<pair<int, int>>* draw_line_DDM(int Xo, int Yo, int X1, int Y1)
{
double m;
if((X1-Xo) == 0 && (Y1-Yo) == 0)
{
vector<pair<int, int>> *point = new vector<pair<int, int>>(1, make_pair(X1, Xo));
//return a vector of one pair only
return(point);
}
if((X1-Xo) == 0 && (Y1-Yo) != 0)
{
m = 1000000000.0;
}
if((X1-Xo) != 0 && ((Y1-Yo) == 0 || (Y1-Yo) != 0))
{
double m = (Y1-Yo)/(X1-Xo);
}
if(abs(m)<=1)
{
vector<pair<int, int>> *pixels_x = new vector<pair<int, int>>(sizeof(vector<(X1-Xo),pair<0, 0>>));
double y = Yo;
for(int counter_x = Xo; counter_x <= X1 ; counter_x++)
{
pixels_x->at(counter_x).first = counter_x;
y += m;
pixels_x->at(counter_x).second = round(y);
}
//create a vector of x pairs
return(pixels_x);
}
if(abs(m)>1)
{
double x = Xo;
vector<pair<int, int>> *pixels_y = new vector<pair<int, int>>(sizeof(vector<(Y1-Yo),pair<0, 0>>));
for(int counter_y = Yo; counter_y <= Y1 ; counter_y++)
{
pixels_y->at(counter_y).second = counter_y;
x += (1/m);
pixels_y->at(counter_y).first = round(x);
}
return(pixels_y);
}
}