我不明白爲什麼我收到此錯誤。我以前使用過相同的代碼,它給了我沒有問題,但現在由於某種原因,我得到一個錯誤。獲取錯誤:新聲明器中的表達式必須具有整型或枚舉類型C++
outputf3 << "The sorted list is as follows: \n\n";
sorting = new float [function.sort()]; // Here is where the error is.
for (i=0; i < length ; i ++)
{
outputf2 << "\n" << sorting[i] ;
}
出於某種原因,它在說
error: expression in new-declarator must have integral or enumeration type
但我在這裏使用的同樣的事情在該程序的一個部分。
inputs = new float[length];
inputf.clear();
inputf.seekg(0, std::ios_base::beg);
我不知道它爲什麼這樣做。 我正在做的是從文件中讀取隨機數字,然後在函數的另一部分對它們進行排序,並將它們寫入輸出文件。
什麼是'function.sort()'?它的回報價值是多少? – mfontanini 2012-03-23 18:27:57
如果'function.sort()'不返回整數類型...錯誤是正常的 – INS 2012-03-23 18:28:02
'float DSP1D :: sort() { \t int i = 0; \t int x = 0; \t \t 爲(I =長度; I> = 0;我 - ) \t { \t爲(X = 0; X <長度-1; X ++) \t \t { \t \t如果(輸入[X ]>輸入[X + 1]) \t \t \t { \t \t \t \t浮子溫度=輸入[X + 1]; \t \t \t \t inputs [x + 1] = inputs [x]; \t \t \t \t inputs [x] = temp; \t \t \t} \t \t} \t} \t返回*輸入; }' 是function.sort,它回調輸入並且類型爲float – 2012-03-23 18:30:22