将float作为指针传递给矩阵

时间:2010-05-10 12:33:39

标签: c++ c

老实说,我无法为这个问题想出一个更好的头衔,因为我有两个问题,我不知道原因。

我遇到的第一个问题是

//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声明为指针。

老实说,我不知道该怎么做。

2 个答案:

答案 0 :(得分: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.

提示:将“*****”视为“值”,将“&amp; ”视为“地址”

答案 1 :(得分:1)

您为什么要尝试m_mtxView._41的地址? m_mtxView._41 = g_posX;有什么问题?

相关问题