|
|
Classes |
|
private.
public - may be accessed inside the class and by any
other class
protected - may be accessed inside the class and by any
class derived from this class
private - may be accessed inside the class and by
friend
class Matrix {
private:
double *_array; // internal matrix representation
int _nr; // number of rows
int _nc; // number of columns
void no_op ( void ); // private function
public:
int foo; // public variable
// constructor
Matrix (int nrows, int ncols);
// destructor
virtual ~Matrix ();
// get a specific value from the matrix
double getVal ( int row, int col ) const;
// set a specific value in the matrix
void setVal ( int row, int col, double val );
// add another matrix to this matrix
Matrix& operator+ (const Matrix& b);
// print out the matrix on the specified stream
friend ostream& operator<< ( ostream& os, const Matrix& m );
};
struct we can then declare Matrix m
and have
| Invalid | Valid | |
|---|---|---|
double *ptr = m._array;
|
m.foo = 4;
|