Sign in to follow this  
lordikon

Var/Class init performance question

Recommended Posts

Which is faster? 1.) String myStr = "Foo"; or 2.) String myStr("Foo"); Does the first method call the default constructor for String, and then the operator= operator? The second method I'm assuming just calls a copy constructor?

Share this post


Link to post
Share on other sites
Yes I meant C++, sorry about the lack of info.

Nice that they generate identical code. What about this?

3.)
String myStr;
myStr = "Foo";

Obviously this is a poor choice anyway because it could be done on one line, and it leaves 'myStr' uninitialized when it is created, which is bad.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this