0

Hello i'm very new to C++ and have run into quite a problem, so i have written a simple function to return a players x, y & z origin, here it is:

float Orgx, Orgy, Orgz;
const float* ReturnORG(Vector3 Blah)
{
    float Orgx = Blah.x;
    float Orgy = Blah.y;
    float Orgz = Blah.z;

    return (float)((Orgx), (Orgx), (Orgx));
} 

the problem is that i get an error saying:

"Error: return value type doesn't match function type"

I Can't seem to figure out what I'm doing wrong, any suggestions?

C0d1ng
  • 441
  • 6
  • 17

1 Answers1

1

Considering the comma operators, (float)((Orgx), (Orgx), (Orgx)) is equivalent to (float)Orgx. float doesn't match float*, so the error occured.

You should want to allocate array statically

const float* ReturnORG(Vector3 Blah)
{
    static float Org[3];
    Org[0] = Org[1] = Org[2] = Blah.x;

    return Org;
}

or dynamically

const float* ReturnORG(Vector3 Blah)
{
    float *Org = new float[3];
    Org[0] = Org[1] = Org[2] = Blah.x;

    return Org;
}
MikeCAT
  • 73,922
  • 11
  • 45
  • 70