Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualcozzie

Posted 11 July 2013 - 03:46 PM

Hi,

 

I'm trying to make a const function returning a float[3] array with the position of my camera.

But I can't manage to do this, without passing the array as a function parameter.

 

To be exact, this is what I do now:

void CD3dcam::GetPositionF(float pPos[]) const
{
	pPos[0] = mPosition.x;
	pPos[1] = mPosition.y;
	pPos[2] = mPosition.z;
}

But this is ofcourse annoying if I want to pass GetPositionF to a function as a parameter, where a float array is expected.

So I tried something like

 

float* CD3dcam::GetPositionF() const

{

   float pos[3];

   pos[0] = mPosition.x;

   pos[1] = mPosition.y;

   pos[2] = mPosition.z;

 

   return pos;

}

 

This compiles, but gives a warning that I'm returning the address of a local variable in memory, instead of a pointer to the actual values.

Any ideas anyone?


#1cozzie

Posted 11 July 2013 - 03:43 PM

Hi,

 

I'm trying to make a const function returning a float[3] array with the position of my camera.

But I can't manage to do this, without passing the array as a function parameter.

 

To be exact, this is what I do now:

void CD3dcam::GetPositionF(float pPos[]) const
{
	pPos[0] = mPosition.x;
	pPos[1] = mPosition.y;
	pPos[2] = mPosition.z;
}

But this is ofcourse annoying if I want to pass GetPositionF to a function as a parameter, where a float array is expected.

So I tried something like

 

float[] CD3dcam::GetPositionF() const

{

   float pos[3];

   pos[0] = mPosition.x;

   pos[1] = mPosition.y;

   pos[2] = mPosition.z;

 

   return pos;

}

 

But unfortunately returning an array doesn't seem to work.

Any ideas anyone?


PARTNERS