[英]passing a float as a pointer to a matrix
老實說,我無法想到一個更好的標題,因為我遇到2個問題,但我不知道原因。
我的第一個問題是
//global declaration
float g_posX = 0.0f;
.............
//if keydown happens
g_posX += 0.03f;
&m_mtxView._41 = g_posX;
我得到這個錯誤
cannot convert from 'float' to 'float *'
因此,我假設矩陣僅接受指針。 因此,我將變量更改為此。
//global declaration
float *g_posX = 0.0f;
.............
//if keydown happens
g_posX += 0.03f;
&m_mtxView._41 = &g_posX;
我得到這個錯誤
cannot convert from 'float' to 'float *'
這幾乎說我不能將g_posX聲明為指針。
老實說,我不知道該怎么辦。
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.
提示:將“ *****”表示為“值”,將“ & ”表示為“地址”
為什么要嘗試使用m_mtxView._41
的地址? m_mtxView._41 = g_posX;
?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.