的阵列我注意到这一点已经引起了混乱几个人,但阅读此一对夫妇的帖子和CPLUSPLUS教程我的大脑还在炒后。C++ - 指向数组的指针 - 指针
假设我有一个头文件中的下列变量 -
int numberOfLinePoints;
D3DXVECTOR3* line; //confused as to what it is
然后在实现C++文件I初始化它们如下 -
//both initialized in constructor
numberOfLinePoints = 25;
line = new D3DXVECTOR3[numPoints]; //array of pointers?
是什么我行变量现在代表什么呢?
据我可以从阅读计算器它应该代表指针数组链接告诉。然后我读然而下面...
...其中(A)阵列指针,并(B)指向数组的指针,都讨论。这让我再次感到困惑,因为他们似乎同样工作。
事实上,我将我的指针定位在一个独立的位置,我分配的位置(正确?)似乎是我的困惑所在。 我是正确,这是一个指针到D3DXVECTOR3对象的数组?
要完成 - 如果变量线保存关于一个线段信息,我将如何创建线段数组?我目前有以下 -
//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
}
任何帮助,非常感谢。
你从来没有在头文件中的变量声明存储。您的“HEADER FILE”行必须全部位于CPP文件的顶部。标题用于声明事物存在的抽象潜力,而不是实际的存储空间,或它们在实际程序中被使用或存在的现实情况。 – Mordachai 2009-12-01 21:45:26
我不知道。在我的课程中,我总是被教导对象声明放在对象头部,并在CPP文件中初始化。我会带着我的一位导师,谢谢。 – 2009-12-01 22:10:03