[英]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. 老实说,我无法想到一个更好的标题,因为我遇到2个问题,但我不知道原因。
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. 这几乎说我不能将g_posX声明为指针。
honestly, I don't know what to do. 老实说,我不知道该怎么办。
1.) 1.)
m_mtxView._41 = g_posX;
2.) 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
? 为什么要尝试使用
m_mtxView._41
的地址? What's wrong with m_mtxView._41 = g_posX;
m_mtxView._41 = g_posX;
? ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.