E
et al.
Hi again! I am still learning through examples, and still I am
struggling with matrix classes!
I have a probably naive question: how do I "force" C++ to use a const
member? I mean, I have learned (through your suggestions) about const
members, for example my at() member in the matrix class:
class matrix
{
public:
matrix(unsigned int rows, unsigned int cols);
matrix(matrix const& src);
virtual ~matrix();
virtual double& at(unsigned int r, unsigned int c);
virtual double at(unsigned int r, unsigned int c) const;
// ...
}
Now, when I print my matrix using std::cout, the non-const member is
called, while I was expecting otherwise! My logging member is nothing
but a simple double loop:
void matrix::log()
{
// ...
for (i = 0; i < getRows(); i++)
{
for (j = 0; j < getColumns(); j++)
cout << showpos << scientific << at(i, j) << " ";
cout << endl;
}
}
What am I missing here?
Thanks!
struggling with matrix classes!
I have a probably naive question: how do I "force" C++ to use a const
member? I mean, I have learned (through your suggestions) about const
members, for example my at() member in the matrix class:
class matrix
{
public:
matrix(unsigned int rows, unsigned int cols);
matrix(matrix const& src);
virtual ~matrix();
virtual double& at(unsigned int r, unsigned int c);
virtual double at(unsigned int r, unsigned int c) const;
// ...
}
Now, when I print my matrix using std::cout, the non-const member is
called, while I was expecting otherwise! My logging member is nothing
but a simple double loop:
void matrix::log()
{
// ...
for (i = 0; i < getRows(); i++)
{
for (j = 0; j < getColumns(); j++)
cout << showpos << scientific << at(i, j) << " ";
cout << endl;
}
}
What am I missing here?
Thanks!