
please wait
matrix class
. I would like to implement both matrix multiplication and element by element (point-wise) multiplications.
|
|
|
|
matrix( const matrix& right)
, with argument the variable result
. m
. Finally, the code will invoke a.operator=(m)
. matrix( const matrix& right);
to be private and give it no body. Then gcc will not create an extra invisible object m
, and will call no copy constructor; instead, it will call directly a.operator=(result)
, before calling the destructor of the object result
. Note: this optimization is better computationally, but will fail to compile on the microsoft compiler.
.*
in Matlab to distinguish with the operator which multiplication operation is performed on the matrix.
|
|
first
or last
occurrence of a particular value idx
in matrix m
. So, val = "first"
or val = last
. But is there any possibility to assign val
to first
by default and by doing that, can I call the function for example as, find(m, 4)
and it would get me the first
occurrence of 4? Or should I implement the whole function again without the string
parameter and implement it for first
(default) every time?
void operator=(const matrix& right)//some prefer to declare this matrix& operator=(const matrix&)
|
|
|
|
a.MultiplyBy(b);
. A = B = C; // logically, this should also be legal, but it isn't if = returns void |
operator=
's as void.
|
|
find<int>(m,4);
)
A = B = C; // logically, this should also be legal, but it isn't if = returns void I see no logical reason why this should be legal (nor a logical reason why it shouldn't be). It is just a convention. It's use contradicts mathematical common sense and so I dislike it and declare all operator='s as void. |
A = B = C
because that is a convention of the rest of the language. (At my job, somebody who writes an operator incorrectly has to buy coffee for the entire office for a week.) It grinds my gears when one naive programmer thinks he's knows better than the millions of other programmers out there and writes code that doesn't work like it should because it 'makes more sense to them'. It makes less sense to write code like this because it is inconsistent with every other aspect of the language. (At my job, somebody who writes an operator incorrectly has to buy coffee for the entire office for a week.) |
I'm going to assume that I can compound statements like A = B = C because that is a convention of the rest of the language |
|
|
to mimic the behavior of the operator in an intuitive fashion |
a=b=c
is completely counterintuitive. void operator=
is better, then now people who use matrix& operator=(/*...*/)
would be "not-understanding-how-c++-works" (although I wouldn't be the one telling that to anybody).
void
- although I am not suggesting anything to anybody; I am saying how I use it.
const
. int HashFunction() const;
instead of int HashFunction();
, I found one of my classes actually modifies *this
during the computation of the hash value (which is not desirable).
void *make_snafucated(void *,void *,void *);
, but would you really want to?