C++ 数组类型';浮动[大小]和#x27;不可转让

C++ 数组类型';浮动[大小]和#x27;不可转让,c++,C++,我有一个模板方法,在这个方法中,我试图将对象放置到数组中。不过我还是不断地犯标题错误。以下是我的代码: template <class Object> void SparseMat<Object>::showSubSquare(int start, int size) { for (int rowIndex = start; rowIndex < start + size; rowIndex++) { Object objectsInRow[siz

我有一个模板方法,在这个方法中,我试图将对象放置到数组中。不过我还是不断地犯标题错误。以下是我的代码:

template <class Object>
void SparseMat<Object>::showSubSquare(int start, int size) {
   for (int rowIndex = start; rowIndex < start + size; rowIndex++) {
      Object objectsInRow[size];
      FHlist<MatNode<Object>> wantedRow = matrix[rowIndex];
      for (iterator<MatNode<Object>> iter = wantedRow.begin(); iter != wantedRow.end(); ++iter) {
          MatNode<Object> m = *iter;
          objectsInRow[m.getCol()] = m.data; //ERROR
      }
      for (int colIndex = start; colIndex < start + size; rowIndex++) {
         if (objectsInRow[colIndex] == NULL) {
           cout << defaultValue << " ";
         }
         else {
           cout << objectsInRow[colIndex] << " ";
         }
      }
      cout << endl;
   }
}
模板
void SparseMat::showSubSquare(int-start,int-size){
对于(int rowIndex=start;rowIndexcout编译时的'size'不是常量,这将导致崩溃

计划A:

用std::vector改变它

方案B:

使用“新类型[尺寸]”

方案C:

template <int _size> // this is the const value for the compiling time
void func()
{
   type array[_size];
   // your code ...
}
template//这是编译时的常量值
void func()
{
类型数组[_size];
//你的代码。。。
}

当您收到错误时,
对象的模板参数是什么?@aschepler a floatuse std::vector-我已经好几个小时没有键入它了,我感觉need@Tas
size
不是模板parameter@M.M我不记得Visual C++支持VLAs。你可以用一个大小为1的数组作为最后一个成员。一个结构,然后为数组分配更多内存。我想这仍然有效,但不确定这是未定义的行为还是不使用它。
template <int _size> // this is the const value for the compiling time
void func()
{
   type array[_size];
   // your code ...
}