I am quite newbie to C++. I want to create a namespace that performs compressed row storage matrix operation, but encountered an error:
terminate called after throwing an instance of 'std::bad_alloc'
Below is my code in a header file:
namespace matrixOperation
{
  class SparseMatrix
  {
    public:
    SparseMatrix(){
    }   
    size_t nrow, ncol, nnz;
    vector<size_t> ia, ja; 
    vector<double> a;
    ~SparseMatrix(){
    }   
  }; // end of SparseMatrix class*/
  typedef SparseMatrix CSR;
  typedef SparseMatrix csr_p;
  inline void alloc_csr(size_t nrow, size_t ncol, size_t nnz, CSR *pt)
  {
    pt = new CSR();  // this is where I think the bug occurs
    pt->nrow = nrow;
    pt->ncol = ncol;
    pt->nnz = nnz;
    pt->ia.resize(nrow+1);
    pt->ja.resize(nnz);
    pt->a.resize(nnz);
    return;
  }
} //end of namespace
Thanks for the help!
 
     
    