C++ 分段故障(堆芯转储)-无法修复错误
我在以下代码中遇到问题。我用Boost做矩阵乘法。我正在使用Gtesting测试我的代码。当我测试以下代码位时,我得到以下错误C++ 分段故障(堆芯转储)-无法修复错误,c++,linux,pointers,boost,memory-segmentation,C++,Linux,Pointers,Boost,Memory Segmentation,我在以下代码中遇到问题。我用Boost做矩阵乘法。我正在使用Gtesting测试我的代码。当我测试以下代码位时,我得到以下错误 Segmentation fault (core dumped) 我知道这与我使用的指针有关,但我找不到错误。我试过几次,但都没有成功。我的代码如下。我正在运行Ubuntu 14.04 BLAS::matrix<double>* PolyFilter::getCoef(const std::queue<double> y const std::
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*PolyFilter::getCoef(const std::queue y const std::queue x,const BLAS::vector&w)
{
int size=y.size();
队列yList=y;
BLAS::矩阵位置(大小,1);
BLAS::matrix*vand=makeVandermondeMatrix(x);
BLAS::矩阵*权重=makeDiag(w);
BLAS::矩阵*temp1,*temp2,*temp3,*temp4,*temp5;
BLAS::matrix*temp6=新BLAS::matrix(大小,大小);
std::cout您声明了几个指针:
BLAS::matrix<double> *temp1,*temp2,*temp3,*temp4,*temp5;
*temp1 = BLAS::prod(BLAS::trans(*vand), *weights);
*temp2 = BLAS::prod(*temp1, *vand);
这是你的问题
另外,您应该花一些时间学习如何使用调试器。使用调试器解决这个问题应该很简单。您声明了几个指针:
BLAS::matrix<double> *temp1,*temp2,*temp3,*temp4,*temp5;
*temp1 = BLAS::prod(BLAS::trans(*vand), *weights);
*temp2 = BLAS::prod(*temp1, *vand);
这是你的问题
另外,您应该花一些时间学习如何使用调试器。使用调试器解决这一问题应该很简单。崩溃发生在哪里?请在调试器中运行调试生成以捕获实际的崩溃,并使用调试器在代码中定位崩溃的位置。您说您尝试了几件事。您尝试了什么?您是否尝试过使用gdb
?最明显的错误是您没有初始化temp1
(不要为它分配指向的空间)但是,请为*temp1
指定一个值。这是一个疏忽吗?还是您需要学习C/C++中指针的基础知识?崩溃发生在哪里?请在调试器中运行调试构建以捕获实际的崩溃,并使用调试器在代码中定位崩溃的位置。您说您尝试了两种方法。您尝试了什么?您是否尝试过使用gdb
?最明显的错误是您没有初始化temp1
(不要为它分配空间),而是为*temp1
赋值。这是一个疏忽吗?还是您需要学习C/C++中指针的基础知识?