Topic: HELP! Derived Matrices from base Vector (Constructor problem!)
Author: jeanf00@DMI.USherb.CA (FREDERIC JEAN)
Date: Tue, 27 Jul 1993 20:23:24 GMT Raw View
Hi!
I'm now making a simple program to do matrices
operations and i have this problem. Since my base class is a
vector and matrice is a derived one, i can't figure out how
to do the constructor for the matrice...
(see source code below for more information...)
-------------- here's my 2 classes and some code after ------------
class Vector
{
Reel *elements;
int nbelement;
public:
Vector(const int &);
Vector(const Vector &);
virtual ~Vector();
virtual Vector operator+ (const Vector &);
virtual Vector operator- (const Vector &);
virtual Reel operator* (const Vector &);
virtual Vector & operator= (const Vector &);
virtual Reel & operator[] (const int &);
friend ostream & operator<< (ostream &, const Vector &);
};
class Matrice : Vector
{
Vector *rows;
int nbrows;
int nbcol;
public:
Matrice(const int, const int);
Matrice(const Matrice &);
~Matrice();
Matrice operator+ (const Matrice &);
Matrice operator- (const Matrice &);
Matrice operator* (const Matrice &);
Matrice& operator= (const Matrice &);
Matrice operator~ ();
Matrice operator* ();
Vector & operator[] (const int &);
friend ostream & operator<< (ostream &, const Matrice &);
};
(...)
// CONSTRUCTOR FOR THE VECTOR
Vector::Vector(const int &n)
{
nbelement = n;
/***************************************************
now, i'm initializing an array of elements (vector)
****************************************************/
elements = new Reel[nbelement];
for (int i=0; i<n ;i+=1)
elements[n] = 0;
}
(...)
// CONSTRUCTOR FOR THE MATRICE
Matrice::Matrice(const int row, const int col)
{
nbrows = row;
nbcol = col;
/*****************************************************
Here is my problem! I can't initialize my matrice. So
how can i initialize an array (private Matrice: "rows")
that point out to 'row' Vectors????
*****************************************************/
rows = new Vector[rows]; // With this, it doesn't work!!!
for int i=0; i<nbrows ;i++)
row[i] = 0;
}
(...)
------------------------------- END -----------------------------
So, if you know how to resolve my problem, i would be glad if
you'd tell me how!!!
Please help!
Thanks,
Fred.
(jeanf00@dmi.usherb.ca)