> Line 9 is a forward declaration of a class, it is not creating 3 instances of a class
wrong. It does defines three objects.
It comes from C, where you need to do
struct foo asdf;
to create it.
> a header file named the same as the class name
that's just a (good) convention, file names are not important.
> A class declaration goes in a header file
that would solve the error that you are getting.
main.cpp knows nothing about a `Matrix' class.
> Your constructor with no arguments, doesn't do anything - so don't provide one.
It does do something. It initializes all the member variables using their default constructor. That means that the `Value' vector would be empty.
> The compiler will implicitly create one if necessary
No if you provide
another constructor definition.
So given that you have a
Matrix(unsigned r, unsigned c, bool fill);
constructor, if you want a default one too you need to define it.
If you just want the default behaviour, you may do
Matrix() = default;
in the declaration.
> The calls to Rows and Cols on line 27 ultimately return the size of the default creation size of a vector
> (usually small and guaranteed to be positive) - so the test on line 27 isn't of any use.
The default constructor of a vector makes it empty, i.e., its size is 0. Meaning that the test on line 27 will always fail.
However, you may call the Init() function on your own, so the test
Rows()<=100
is not useless.
> With error messages say why there is an error.
¿what are you trying to say? The OP has posted the error message, which he doesn't understand.
By the way
36 37 38 39 40
|
for(int i=0;i<r;i++){
for(c=0;Cols()<c;c++){
Values[Rows()][Cols()]=rand();
}
}
|
¿what do you think you are doing?