|
-
Mar 22nd, 2001, 12:07 PM
#1
Thread Starter
New Member
I was wondering if someone could explain initialization lists for structs and class member functions. I don't see why you would initialization in the initializer list instead of in the body of the program. For example:
Code:
StudentType::StudentType()
: Grades(10, -1), Gender(female), Class(0)
{
}
I am guessing there's a good reason but I really don't understand the point.
Thank you so much for any help
-
Mar 22nd, 2001, 02:12 PM
#2
Frenzied Member
Well I know why you would use this in a class. In your example if you had the init list under the class constructor your functions in that list would run when the class is inited. You would do this if those functions set values needed in other functions in your class. This way you would not have to call these functions individualy, or inside each other function. So if it was done this way:
PHP Code:
StudentType Students; //When this this called it would call those functions in the init list
But I cant think of a real good reason to do it as init list for a single function in a class. It might just be another way to call the functions
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Mar 22nd, 2001, 05:54 PM
#3
Thread Starter
New Member
Sorry, that wasn't really what I meant to ask but thanks for your answer
Why don't you put the initialization statement in the body of the initializer? Why wouldn't you:
Code:
StudentType::StudentType()
: Grades(10, -1)
{
Gender = female;
Class = 0;
}
Hope someone can give me more help.
-
Mar 22nd, 2001, 05:59 PM
#4
Frenzied Member
I think this might be one of those things where you could do it this way, or that way. It just depeneds on how you program. I honestly dont see a reason it would make a difference.
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|