我已经查看了一些关于 c++ 中非法成员初始化的类似问题,同样的错误 C2614,但似乎与我的问题不一样。
我有一个模板类“Mat2D”:
#pragma once
#include <iostream>
#include <iomanip>
#include <assert.h>
template<class T>
class Mat2D
{
private:
int _rows;
int _cols;
T** _data;
public:
Mat2D()
:_rows(0), _cols(0), _data(NULL)
{
}
Mat2D(const Mat2D<T>& rhs)
:_rows(rhs._rows), _cols(rhs._cols)
{
cloneData(rhs._data);
}
Mat2D(int rows, int cols)
{
_rows = rows < 1 ? 1 : rows;
_cols = cols < 1 ? 1 : cols;
allocateData();
}
Mat2D(int rows, int cols, const T& initValue)
:Mat2D(rows, cols) //--> error C2614: 'Mat2D<T>' : illegal member initialization: 'Mat2D<int>' is not a base or member
{
all(initValue);
}
~Mat2D()
{
for(int i = 0; i < _rows; i++)
delete _data[i];
delete _data;
}
//...
};