I write a class using sparse matrices. It happens that for both of them, their non-zeros are on the same (i,j)s. As I have to compute these (i,j)s, I'd prefer to have to do it only once.
Currently, I do it separately and my constructor looks like this:
class C
{
private:
matrix matA;
matrix matA;
holder ijs;
private:
matrix initMatA();
matrix initMatA();
holder init_ijs(int, int);
public:
C(int, int);
};
C::C(int foo, int bar) : init_ijs(foo, bar), matA(initMatA()), matB(initMatB())
{
}
as I've read that it is best practice to use initialization list (and actually, when I first wrote it, if I remember correctly it was impossible to instantiate my matrices otherwise (EDIT: a default constructor seems to fix it?)). If it was Python, I could write something like
def initMats(foo, bar):
...
return matA, matB
If think the C++ way would be something like
void initMats(int foo, int bar, matrix &matA, matrix &matB)
{
...
}
but I guess I cannot pass reference to objects that have not yet been constructed. Any clue on a way to solve this? My idea was to first create the (i,j)s list as an attribute to my class so I can later use it in my initA and initB methods, but I will not be needing it afterward I don't think it's the best way to do.