(*我用我的陣列結構,並且它必須是動態)模板 - 類對象 - 類的結構對象
我想Array
結構來填充Expe
類對象。我使用模板,但不知何故,我的結構頭不識別我創建的模板。
Struct標頭:
template <class T>;
struct Arr{
int days;
T * M;
};
typedef Arr* Array;
結構CPP:
void constr(Array &o){
//Construct of 31*1 Matrix
o=new Arr;
o->days = 31;
o->M = new T[o->days];
應該沒事我想,但我得到的錯誤:
..\ListStruc.cpp:26:13: error: expected type-specifier before 'T'
包含代碼的問題的另外90%在哪裏? – Jon 2012-04-12 13:14:54
補充,我按錯誤輸入... – 2012-04-12 13:16:28
我不知道這些是否與問題有關(我不能彌補問題的正面或反面)但我相信他們會有所幫助:[爲什麼模板只能在頭文件中實現?](http://stackoverflow.com/questions/495021),[三條規則是什麼?](http://stackoverflow.com/questions/4172722)和[爲什麼使用'new'導致C++內存泄漏?](http://stackoverflow.com/questions/8839943/why-does-the-use-of-new-cause-memory-leaks-in-c/ 8840302) – 2012-04-12 13:19:52