LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   c++ structure-array question (https://www.linuxquestions.org/questions/programming-9/c-structure-array-question-130481/)

deveraux83 12-31-2003 10:05 PM

c++ structure-array question
 
Hiya,

Say I had a data structure containing 3 floats, such as:

struct threefloats
{
float x, y, z;
} float3f;

and I had a function which operates on an array of floats, such as:

void foo(float xyz[3]);

Is there anyway that I could modify the threefloats structure so as I could call foo with an argument of type threefloats? I know that I could make it return float by adding:

operator float()

to structure, but what about casting threefloats to an array such that x, y, and z in the threefloats structure gets put into the array for foo() to operate on.

Thanks,
deveraux83

llama_meme 01-01-2004 06:50 AM

Just cast a pointer to the structure to the type (float *), and then pass the resulting value as the argument to the function.

Alex

deveraux83 01-01-2004 08:55 AM

Yup, that did it ..thanks LM!!

deveraux83:D


All times are GMT -5. The time now is 04:02 PM.