I Just Wanted to Point to Something!

By Jonathan Müller

Every non-trivial programming language needs a way to refer to another object that is stored in a different place. In some programming languages this behavior is the default ­— they have reference semantics.

But this is not the case in C++. In C++ you need a special type to refer to another object: a pointer. I mean a reference …​ or std::reference_wrapper? Or maybe a smart pointer. But probably std::string_view if the object is a string. And sometimes an iterator if you’re pointing to anything in a container. Or maybe something completely different.

Confused? Maybe not. Maybe you are experienced and know what to choose. But did you always choose correctly? This talk will provide comprehensive guidelines.

We’ll answer questions like:

  • When should I use a reference, when a pointer, when something different?

  • If references are non-null pointers, what’s the point of gsl::non_null<T*> to create a non-null pointer?

  • Do I need std::optional<T&>? Or is it just a pointer?

  • What the heck is C++17’s std::byte* and when is it useful?

  • Is there still a need for void*?

In the end you’ll know exactly when to use which pointer-like type and why.

Your Privacy

By clicking "Accept All Cookies" you agree ACCU can store cookies on your device and disclose information in accordance with our Privacy Policy and Cookie Policy.

By clicking "Share IP Address" you agree ACCU can forward your IP address to third-party sites to enhance the information presented on the site, and that these sites may store cookies on your device.