#include<iostream>
class Oddball {
private:
int secret;
public:
Oddball( int value ) : secret(value) {}
Oddball(const Oddball& m) : secret(m.secret) {}
~Oddball() {}
void SetValue(int value) {
int temp = 0;
Oddball WhoIsThis( temp );
WhoIsThis.secret = value; // Really ????
}
void Print() {
int temp = 0;
Oddball WhoIsThis( temp );
std::cout << WhoIsThis.secret << '\n';
}
};
int main()
{
int A = 0;
Oddball m(A);
m.Print();
std::cout << '\n';
m.SetValue(5);
m.Print();
}
What is the temporary WhoIsThis that is modified (and promptly forgotten) or shown?
It has nothing to do with the secret of the Oddball that we "set value" or "print" for.
Perhaps:
1 2 3 4 5 6 7
void Oddball::SetValue(int value) {
secret = value; // you can write this->secret if that feels better
}
void Oddball::Print() const {
std::cout << secret << '\n';
}
- Line 11: it would be better to change to Matrix(int rows, int columns) : Mat(vector<vector<int> >(rows, vector<int>(columns, 0))) {}.
So you can change lines 66-68 to the simplest Matrix m(4, 4);.
- Line 15: what is "cella"? Maybe you would write
1 2 3 4
Matrix(const Matrix& m)
: Mat(m.Mat)
{
}
- Lines 20-22: the functions should be named GetValue, GetRows and GetColumns
- Line 24: you should change it to void SetValue(int r, int c, int value)
- Lines 26-30: you are assigning the value to a temporary object. Why are you using a temporary object? Why not simply writing Mat[r][c] = value;?
- functions Print and Clear: see function SetValue, don't create a temporary object
- Line 57: Mat contains ints not chars. Why are you using ' ' instead of 32? And why not 0?