N
nabeel.girgis
I am passing a vector by reference into a function and I am trying to
use a pointer in that function.
I get an error saying : '=' : cannot convert from 'std::vector<_Ty> *'
to 'int *'
when I try to initialize the pointer to point to the vector. This is
my first time using pass by reference into a function while trying to
declare a pointer in the same function. My code is given below.
void v_abs(vector<int>&x)
{
int *y;
**** y = &x;
while (*y)
{
if (*y < 0)
*y *= -1;
y++;
}
}
The *** represent where the cursor flashes when I double click on the
error message. I am a student and I know that the standard way of
declaring and initializing a pointer is:
int *ptr;
ptr = &element;
But I am having trouble initializing a vector passed by reference.
Thank you.
use a pointer in that function.
I get an error saying : '=' : cannot convert from 'std::vector<_Ty> *'
to 'int *'
when I try to initialize the pointer to point to the vector. This is
my first time using pass by reference into a function while trying to
declare a pointer in the same function. My code is given below.
void v_abs(vector<int>&x)
{
int *y;
**** y = &x;
while (*y)
{
if (*y < 0)
*y *= -1;
y++;
}
}
The *** represent where the cursor flashes when I double click on the
error message. I am a student and I know that the standard way of
declaring and initializing a pointer is:
int *ptr;
ptr = &element;
But I am having trouble initializing a vector passed by reference.
Thank you.