|
|
Friend and other identifiers |
|
friend keyword
class Matrix {
public:
// output operator
friend ostream& operator<< ( ostream& os, const Matrix& m );
};
allows the output operator full access to the private methods of the Matrix
class.
static keyword
static is allocated only
once for all instances of the class and each instance can access the value
of this variable. This variable does not get initialized with the rest of
the class but is done once when the program is started.
class Matrix {
public:
static int num;
};
int Matrix::num = 1;
static only has access to
variables which are also declared static and any data passed
into it. It does not implicitly have access to other class data.
const keyword
const cannot be
directly modified without causing a compiler error. The compiler will
also throw errors for any attempt to pass a const object
into a non-const function
const is safe to operate on objects
as long as it does not modify the object. The const keyword
follows the function definition as in
double getVal ( int row, int col ) const;