Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

uNiQue0815

strange behaviour...

This topic is 5225 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

some time ago, i wrote a string class. today in one of its methods, the application suddenly crashed... i didn''t have problems with the string class for months now, so this seemed strange to me. after hours of debugging, i still could not make out a bug. so i rewrote a part of a function in my app, in which the string was used & crashed. suddenly the problem was gone... i looked a bit closer at my code and noticed, that there was a small difference : original (crashing on return):
void myFunction(const String &dir)
{
	String directory = dir;
	directory.insert(directory.GetLength(), ''/'');
}
 
''copy'' (working):
void myFunction(const String &dir)
{
	String directory;
	directory = dir;	// <<< ??
	directory.insert(directory.GetLength(), ''/'');
}
 
so what does that mean ?? shouldn''t the first method be exactly the same, as the second one ?

Share this post


Link to post
Share on other sites
Advertisement
No, they aren''t the same. In the first version you copy construct the directory string from the dir string. In the second version you default construct the directory string and then assign the dir string to the directory string. Why that makes a difference would depend on how your assignment operator and copy constructors are defined for your string class.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!