[英]Segmentation fault (core dumped)-cannot fix error
我在以下代码方面遇到麻烦。 我正在使用Boost进行矩阵乘法。 我正在使用Gtesting测试我的代码。 当我测试以下代码时,出现以下错误。
Segmentation fault (core dumped)
我知道这与我使用的指针有关,但是我找不到错误。 我尝试了几件事,但是没有运气。 我的代码如下。 我正在运行Ubuntu 14.04。
BLAS::matrix<double>* PolyFilter::getCoef(const std::queue<double> y const std::queue<double> x, const BLAS::vector<double>& w)
{
int size = y.size();
queue<double> yList = y;
BLAS::matrix<double> pos(size,1);
BLAS::matrix<double>* vand = makeVandermondeMatrix(x);
BLAS::matrix<double>* weights = makeDiag(w);
BLAS::matrix<double> *temp1,*temp2,*temp3,*temp4,*temp5;
BLAS::matrix<double>* temp6 = new BLAS::matrix<double>(size,size);
std::cout<<size<<endl;
for( unsigned int i = 0; i < size; i++)
{
pos.insert_element(i,0,yList.front());
yList.pop();
}
*temp1 = BLAS::prod(BLAS::trans(*vand), *weights);
*temp2 = BLAS::prod(*temp1, *vand);
if( rfalInverse(*temp2, *temp3) )
{
*temp4 = BLAS::prod(*temp3, BLAS::trans(*vand));
*temp5 = BLAS::prod(*temp4,*weights);
*temp6 = BLAS::prod(*temp5, BLAS::trans(pos));
}
return temp6;
}
感谢您的任何帮助。 这个错误使我发疯。
您声明了几个指针:
BLAS::matrix<double> *temp1,*temp2,*temp3,*temp4,*temp5;
然后,您立即继续取消引用未初始化的指针:
*temp1 = BLAS::prod(BLAS::trans(*vand), *weights);
*temp2 = BLAS::prod(*temp1, *vand);
有你的问题。
PS:您应该花一些时间来学习如何使用调试器。 用调试器弄清楚这应该很简单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.