C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Calling methods on a nullptr

From: Thiago Macieira <thiago_at_[hidden]>
Date: Tue, 29 Oct 2024 14:51:59 -0700
On Tuesday 29 October 2024 13:20:08 Pacific Daylight Time Frederick Virchanza
Gotham via Std-Proposals wrote:
> string GetCodecName(Manager *const pmanager)
> {
> return
> pmanager->GetDevice()->GetChannel(0)->GetLowPassFilter()->GetCodecName(); }

This can be implemented with a wrapper object instead of raw pointer in
Manager, returning a default device.

Or just stop using direct, raw pointers. Use a wrapping object that does check
that its managed contents are null or not.

  return manager.GetDevice().GetChannel(0).GetLowPassFilter().GetCodecName():

I have a couple thousand examples of this in Qt to point you to. The only
difference would be coding style: we don't prefix your getters with "Get" and we
start names with lowercase.
-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering

Received on 2024-10-29 21:52:04