2010-05-10 86 views
1

老實說,我想不出這個問題更好的標題,因爲我有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 *' 

所以我假設矩陣只接受指針。所以我改變varible這個....

//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作爲指針。

老實說,我不知道該怎麼辦。

+0

向我們展示m_mtxView的聲明和類型。但是,您當前的代碼仍然有與[上一個問題]相同的問題(http://stackoverflow.com/questions/2802418/pointer-on-left-needs-integral-value-on-right)。 – 2010-05-10 12:38:32

+7

你爲什麼一直試圖把一切都解決掉? – sepp2k 2010-05-10 12:39:11

+0

矩陣的定義是什麼? – zebrabox 2010-05-10 12:39:11

回答

6

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. 

提示:讀取 「*****」 爲 「值」 和 「&」 作爲「地址」

+1

很難看出第二點會是什麼。 – 2010-05-10 12:40:03

+0

也很難看到第二個「浮動」是如何釋放的。 – sbi 2010-05-10 12:42:07

+0

更新了答案 – 2010-05-10 12:47:52

1

你爲什麼試圖把地址m_mtxView._41m_mtxView._41 = g_posX;有什麼問題?

+0

我得到這個錯誤不能從'浮動'轉換爲'浮動*' – numerical25 2010-05-10 12:46:31

+0

@numer25:我認爲這發生與&m_mtxView._41 = g_posX; '(注意'&')? – sbi 2010-05-10 14:02:58

相關問題