简体   繁体   中英

passing a float as a pointer to a matrix

Honestly, I couldnt think of a better title for this issue because I am having 2 problems and I don't know the cause.

The first problem I have is this

//global declaration
float g_posX = 0.0f;
.............


//if keydown happens
g_posX += 0.03f;


&m_mtxView._41 = g_posX;

I get this error

cannot convert from 'float' to 'float *'

So I assume that the matrix only accepts pointers. So i change the varible to this....

//global declaration
float *g_posX = 0.0f;
.............


//if keydown happens
g_posX += 0.03f;


&m_mtxView._41 = &g_posX;

and I get this error

cannot convert from 'float' to 'float *'

which is pretty much saying that I can not declare g_posX as a pointer.

honestly, I don't know what to do.

1.)

m_mtxView._41 = g_posX;

2.)

Update: this piece of code is quite unnecessary, although it shows how to use a pointer allocated on the heap.

float* g_posX = new float; // declare a pointer to the address of a new float
*g_posX = 0.0f; // set the value of what it points to, to 0.0This
m_mtxView._41 = *g_posX; // set the value of m_mtxView._41 to the value of g_posX
delete g_posX; // free the memory that posX allocates.

Hint: Read "*****" as "value of" and " & " as "address of"

Why are you trying to take the address of m_mtxView._41 ? What's wrong with m_mtxView._41 = g_posX; ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM