Somebody gave me a a program having an error yesterday. Working in MVS 2010, I found the problem and an alternative for it as well. The problem was the overloaded insertion operator the class. Its prototype was as follows...
void matrix :: operator << (matrix&) ;
It was called from somewhere like this...
matrix m ;
m.operator << (m) ;
I worked out that compiler does not allow to send the same object as a reference parameter upon which the function was called. But I don't understand the reason behind that and that what problem does it create. I would appreciate if anybody could explain that. Thanks.
EDIT:
What is actually happening is that upon debugging, it goes inside the function, comes out and at execution of main
, goes into the external dependency file dbgdel.cpp
and stops at this line.
_ASSERTE(_BLOCK_TYPE_IS_VALID(pHead->nBlockUse));
const
in there. – Trabzonconst
– Maceratematrix
is really a matrix,operator<<
will probably iterate over the entries of the argument matrix and at the same time modify the contents, and possibly the number, of entries in the object matrix. Since both are identical objects, the iteration may fail as you add/remove entries to the data structure you are iterating over. – Gauvin