Loading…
Attending this event?
Back To Schedule
Wednesday, October 4 • 09:00 - 10:00
Back to Basics: Initialization

Log in to save this to your schedule, view media, leave feedback and see who's attending!

Log in to leave feedback.
C++ has many ways to initialize objects, and even experienced C++ programmers often have difficulty remembering exactly what each one means. For example, which constructor of T does each of the following statements invoke?

T t1(1, 2, 3);
T t2{4, 5, 6};
T t3 = t2;

Moreover, the context of the initialization can affect how the compiler interprets certain constructs. As such, we often have difficulty deciding which form of initialization to use. Choosing a form of initialization is especially difficult when we don’t know the exact type of the object that we’re initializing (i.e., when the type of the object is a template type parameter).

In this session, we’ll explore the similarities and differences among each form of C++ initialization and how the initialization rules have changed over time. Focusing on the common elements, we’ll see how C++’s initialization rules are (while not simple) not quite as complex as they might first appear. We’ll see how the Standard Library chooses which form of initialization to use and how that affects similar code that you might write yourself. We’ll also discuss how you can design your classes to make them easy to use in light of the initialization rules.

You’ll leave this session with a clearer understanding of exactly what each form of initialization means. With this knowledge, you’ll be better able to decide when each form of initialization suits your needs, which will help you write code that’s more expressive, robust, and maintainable.

Speakers
avatar for Ben Saks

Ben Saks

Chief Engineer, Saks & Associates
Ben Saks is the chief engineer of Saks & Associates, which offers training and consulting in C and C++ and their use in developing embedded systems. Ben has represented Saks & Associates on the ISO C++ Standards committee as well as two of the committee’s study groups: SG14 (low-latency... Read More →


Wednesday October 4, 2023 09:00 - 10:00 MDT
Maple 3/4/5