VecComplex overloading


perr
09-19-2010, 07:45 AM
Hi all,

When I have declared the variables A, B and C of type VecComplex in this fashion:

VecComplex A(N), B(N), C(N);

How can I perform elementary algebraic operations like plus, multiplication and so on? E.g.:

A = B + C;

When I do this, I get the error message " error: no match for ‘operator=’ .... ".

Is there a built-in NR-routine to deal with this?

Regards, perr

Bill Press
09-21-2010, 09:21 AM
Hi, perr.

We made an early design decision to have very "lean" vector and matrix classes, with only the minimal member functions that were universal across several different vector and matrix class libraries. The advantage of this is that users can substitute their favorite vector/matrix class library without breaking our code. The disadvantage, as you have discovered, is that some obvious, convenient features are left to the user to implement.

Within the nr3.h framework, you add complex vectors by,
Int i,n = c.size();
// might check sizes on a and b, too
for (i=0;i<n;i++) c[i] = a[i] + b[i];


However, you can very easily overload the "+" operator so as to allow
c = a + b;
You can do this either by editing your personal copy of the nr3.h file, or else by deriving your own new class from VecComplex, say MyVecComplex, and defining the "+" operator in it.
Cheers,
Bill P.