老实说,我无法想到这个问题的更好的标题,因为我有2个问题,我不知道原因.
我遇到的第一个问题是这个
//global declaration
float g_posX = 0.0f;
.............
//if keydown happens
g_posX += 0.03f;
&m_mtxView._41 = g_posX;
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
cannot convert from 'float' to 'float *'
Run Code Online (Sandbox Code Playgroud)
所以我假设矩阵只接受指针.所以我把变量变成了......
//global declaration
float *g_posX = 0.0f;
.............
//if keydown happens
g_posX += 0.03f;
&m_mtxView._41 = &g_posX;
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
cannot convert from 'float' to 'float *'
Run Code Online (Sandbox Code Playgroud)
这几乎是说我不能将g_posX声明为指针.
老实说,我不知道该怎么办.
1.)
m_mtxView._41 = g_posX;
Run Code Online (Sandbox Code Playgroud)
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.
Run Code Online (Sandbox Code Playgroud)
提示:将"*****"视为"值",将" & "视为"地址"
| 归档时间: |
|
| 查看次数: |
825 次 |
| 最近记录: |