I sat down today to do some DDR code, first in a while, and spent 3 hours debugging some crashes!
Don’t you just hate it when you leave your code in a none working state! One was some bad XML, incorrect closing elements, and the other was some memory being trashed. The memory problem was due to my string class doing a shallow copy on assignment… well actually it wasn’t, but the compiler was for some reason not using my string assignment operator and instead doing it itself! Actually I have no idea what the compiler is doing at that point… grr…
It seems that the compiler differentiates between these two bits of code…
figure1
int example_function ( const string& source )
{
string new_string = source ;
}
figure2
int example_function ( const string& source )
{
string new_string ;
new_string = source ;
}
figure2 creates the correct constructor code for new_string and the correct assignment operator call for new_string = source. Figure one just makes new_string exactly equal to source. I think I must be missing something somewhere!
C++, programming, source, string, constructor, operator
Good to see that you are looking at the old DDR again!
Hey, great to see you working on a remake of one of my all time favourite games!
Any chance to do the unreleased EYE of the MOON? Were any details of the 3rd part ever released?
Really good to see you working on this great game again.
Just out of interest, can you tell me how to start Lords Of Midnight with all the Lords?
Cheers
I supose this is the expected behavior, because you are declaring an doing an assigment in the same time.
This is a compiler optimization to avoid calling the empty constructor and after another call to the assigment operator, witch is supose to have the same behavior than de copy construcor.
To do this as you expected you must have an empy constructor, and have your ” string(const string& str) ” with the keyword “explicit” .
You can avoid this declaring some or all the constructors with the keyword “explicit” , witch make them unavailable for ‘implicit convertions’.
Keep up your excelent work.
Nuno Custodinho.
Hi Chris, Thought it was about time one of the Midnight M?MU gang sent a response, just to prove we do read it from time to time!! Keep up the good work, can’t wait to see it.