今天编写一个简单的代码,报错了:
template
class matrix final
{
public:
matrix(uint32_t size):
SIZE(size)
{
_data = static_cast(malloc(SIZE * sizeof(T*)));
for (uint32_t i = 0; i < SIZE; ++i)
{
_data[i] = new T[SIZE];
}
}
inline const uint32_t size() const
{
return SIZE;
}
T* operator[](uint32_t index) const
{
return _data[index];
}
~matrix()
{
for (uint32_t i = 0; i < SIZE; ++i)
{
delete[] _data[i];
}
free(_data);
}
private:
const uint32_t SIZE;
T** _data;
};
改为编译语句为:
:gcc -lstdc++ -std=c++11 main.cc -o main
解决了。