Class Member Initialization
Jul 19, 2016 at 4:26am UTC
Hey guys,
I have a little question: Is there any real difference in the way you initialize class members? Does one create a larger executable or faster run-time?
EX:
.h
1 2 3 4
class foo {
int a;
foo(int rhs);
};
.cpp (type 1)
foo::foo(int rhs) : a(rhs) { }
OR
.cpp (type 2)
foo::foo(int rhs) { a = rhs; }
Jul 19, 2016 at 4:47am UTC
Hi,
(type 1) is generally faster. Use it as often as you like.
Jul 19, 2016 at 4:48am UTC
Does that help? :)
Jul 19, 2016 at 5:02am UTC
Yes, thank you. What is the difference between the two in that case though?
Jul 19, 2016 at 5:10am UTC
http://www.geeksforgeeks.org/when-do-we-use-initializer-list-in-c/
Topic archived. No new replies allowed.