我注意到这引起了几个人的困惑,但在阅读了一些帖子和cplusplus教程后,我的脑袋还是糊涂的。
假设我有以下变量在头文件中 -
int numberOfLinePoints;
D3DXVECTOR3* line; //confused as to what it is
然后在C++实现文件中,我将它们初始化如下 -
//both initialized in constructor
numberOfLinePoints = 25;
line = new D3DXVECTOR3[numPoints]; //array of pointers?
现在我的line变量代表什么?
据我从stackoverflow上的链接所了解,它应该代表一个指针数组。然而,我接着读到了以下内容...
(1) 初学者指针
...其中(A)讨论了指针数组和(B)数组指针,这让我再次感到困惑,因为它们似乎都工作得很相似。
我定义指针的位置与我分配它们的位置不同,这似乎是我困惑的根源。 我正确地认为这是一个指向D3DXVECTOR3对象的指针数组吗?
最后 - 如果变量line保存有关一条线段的信息,那么如何创建一组线段的数组? 我目前有以下内容-
//HEADER FILE
int numberOfLineSegments;
D3DXVECTOR3** lineCollection; //array of pointers - each of which
//points to an array of pointers?
//CPP FILE
numberOfLineSegments = 8; //constructor
for(i = 0; i < numberOfLineSegments; i++) //initialization
{ //and allocation CORRECT?
lineCollection[i] = new D3DXVECTOR*[numPoints]; //of memory for Y/N
} //lineCollection
VOID createLineSegments(startPoint, endPoint) //could return array instead
{
//pseudo to generate one line segment
while != numberOfLinePoints
line[sentinel++] = interpolate(startPoint, endPoint, time_T)
//pseudo to generate array of line segments
while != numberOfLines
lineCollection[sentinel++] = line
}
任何帮助都非常感激。