NRMat design


alroirm
03-04-2007, 11:32 PM
Hi all,

I'm working on a program. One of the things it has to do is to load a datafile into an NRMat. At first, i tried to write a derived class with a new constructor and the datafile as an argument; This was silly, because in C++ the base class constructor are called first, so there's no way to do this because i don't know the size of the datafile before reading it into the derived class constructor (I'm just learning C++ for this programs, no previous knownledge of it). The solution for me was to make a template function which reads the datafile and returns an NRMat object; this worked because of the copy '=' operator inside the NRMat class.

All of this makes me think the following: In C++ the '=' operator is NEVER inherited, and it is the only method provided for extending the bounds of an NRMat; so, this means that one can't never make derived classes from NRMat (or NRVec too) if planning to hot-extend the bounds of the matrix.

Why wasn't the design decision to provide protected 'realloc' (new and delete based) methods for those classes, and use that method/s for the '=' operator? Protected members are inherited, so this permits writting a derived class which implements the '=' operator, as well as like in my case, writting derived classes which needs to know things before fixing the bounds of the matrix.

Is this accurate? Am i wrong with something (remember, i do not know C++ at all, i'm an experienced C coder, but nothing about c++)?

Thanks,
Roi Rodriguez

Kevin Dolan
03-09-2007, 05:00 AM
You can always create your own vector and matrix classes, starting with the ones supplied by NR as a template. The code is even designed to make this easy to do.

You can also try out my VecMat software, available here

http://kdolan1973.mine.nu/vecmat/software.htm

It provides vector and matrix classes which do what you want, and it is designed to be usable with NR.

Kevin