Thanks dusktreader for answering :)
Actually, I looked at your code while reading the line "it keeps the code from executing a switch on every single iteration of the loop" and therefore got confused.
The switch statement is really just a convenience wrapper for a regular conditional (if). A for loop already has a conditional that is executed in every iteration. Usually this is a check to ensure that the index hasn't exceeded the limit of the loop: for( int i=0; i<n; i++ ){...} If you can help it, you don't want there to be another conditional inside of the for loop, otherwise, the program has to check it on every iteration.
So, this:
for( ){
if( C == A )
someOperation();
if( C == B )
someOtherOperation();
}
Has to check the value of C on every iteration of the loop. Though it doesn't look as clean, it would be more efficient to write:
if( C == A )
for()
someOperation();
if( C == B )
for()
someOtherOperation();
This way, the test on the value of C is only performed once. This is a small optimization, but in a large project, simple boosts can gain a lot!
Mat[][] is a private member of class Matrix object other, can it be directly accessed? I don't think so.
Actually, it can directly access the private members of another class of the same type. Try this code out:
#include <iostream>
using namespace std;
class Dummy{
private: …