Boost logo

Ublas :

Subject: Re: [ublas] define a matrix in my class
From: Rutger ter Borg (rutger_at_[hidden])
Date: 2010-02-02 09:33:44

David Bellot wrote:

> It's a nice solution.
> Anybody correct me if I'm wrong. In Gianluigi's solution, a myclass
> instanciation, a first identity_matrix object is created.
> Then in it's constructor, a second one is created, then a copy constructor
> is called.
> Now if you pass initialization parameters into the constructor
> initialization list like
> myclass::myclas() : qt(3), you will only have one constructor called for
> qt and no copy-constructor.
> I think it doesn't matter if instanciate that one time, but if myclass is
> instanciated a huge number of time, the overhead can be quite desastreous
> ?

I guess so. Just to make the list of possibilities more complete, to prevent
multiple copies (since we're dealing with an identity matrix) and to have no
construction at run-time at all,

struct A {
    static ublas::identity_matrix<double> qt;

ublas::identity_matrix<double> A::qt = ublas::identity_matrix<double>(3);