Sign in to follow this  
gohkgohk

Question on struct

Recommended Posts

That's called a member initialization list. When that constructor is called, the x and y members of that abc struct instance will be intialized with the values of the x and y parameters sent to the constructor. It's not particularly useful for primitive types like ints, and is usually used for objects that are members of a struct or class.

Share this post


Link to post
Share on other sites
The 'pro' of using initializer lists should be obvious: It's faster to write than the actual constructor list(ie, { this->x = x; this->y = y; }), and it also garantuees that before executing ANY code in the constructor, the variables will be set to a value.

If you use the initializer lists properly and update them when you add in new class variables, it could help prevent bugs related to uninitialized values.

Toolmaker

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