[comp.lang.c++] arrays of objects with multiple initializers

nelson@melodian.cs.uiuc.edu (Taed Nelson) (07/31/90)

Over the weekend, I was working with a Matrix Class (courtesy of
  Bob Olson), and it was a pain to initialize a matrix by setting
  each element.  Would it be possible to use a constructor that 
  somehow behaved like the autoinitialization of arrays?

I'm looking for something like:
	Vector :: Vector (float ...)   <-- any number of elems
	Matrix :: Matrix (Vector ...)  <-- any number of vectors
so that I could type
	Matrix fred = ((11, 12, 13), (21, 22, 23), (31, 32, 33));

I realize that this syntax is totally illegal, but could I somehow
  use a similar syntax?  Or could C++ recognize that the extra-parened
  things fit the constructor for a Vector, and that a Matrix takes
  Vector parameters?

GNU mentioned a Matrix library in their upcoming C++ library.  How do
  they do it???

joe@proto.COM (Joe Huffman) (08/02/90)

In article <1990Jul30.222115.2232@brutus.cs.uiuc.edu>, nelson@melodian.cs.uiuc.edu (Taed Nelson) writes:
> Over the weekend, I was working with a Matrix Class (courtesy of
>   Bob Olson), and it was a pain to initialize a matrix by setting
>   each element.  Would it be possible to use a constructor that 
>   somehow behaved like the autoinitialization of arrays?
  

This is the way my (modified from Bruce Eckels book) matrix class handles it:

class matrix
{
private
  int rows, cols;
  double *mat_p;
[...]
public:
	matrix (int rows, int cols, const double *init_p = 0);
[...]
};

-- 
joe@proto.com
uunet!proto!joe
FAX: 208-263-8772