的陣列我注意到這一點已經引起了混亂幾個人,但閱讀此一對夫婦的帖子和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