I’m trying to initialise/assign values to a ublas vector by defining the vector in my .h file:
someClass{
ublas::vector<double> *L;
} ;
Then in my .cpp file:
someClass::someClass()
{
L = new ublas::vector<double>[4];
L->data()[0] = 1;
}
The code compiles fine, but when I run it, the last line in my .cpp file gives an error. There is probably something very simple I’m missing but I can’t figure out what…
Many thanks in advance! 🙂
You’ve created an array of four ublas::vectors, each of size zero. Assigning to the first element of an empty vector throws an exception.
Did you mean to write
instead?
Not to mention that the use of new and pointer is questionable, for most uses, a member object is more appropriate: