this post was submitted on 13 May 2024
4 points (61.1% liked)

C++

1778 readers
1 users here now

The center for all discussion and news regarding C++.

Rules

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] cmeerw 9 points 6 months ago (2 children)

And even the presented fix hurts my eyes. Should have used a unique_ptr or optional.

[–] [email protected] 3 points 6 months ago

Exactly, raw pointers are very rarely the way to go

[–] lysdexic 1 points 6 months ago* (last edited 6 months ago) (1 children)

You'd be missing the whole point too if you think that the pointer is the root cause. The problem is that the class is not designed to be copy-able, let alone moveable. Your suggestion to use a unique_ptr will also blow up in your face the moment you try to copy an instance.

[–] cmeerw 2 points 6 months ago (1 children)

Depends on what semantic you want. Sure, if you use a unique_ptr member, you will get a deleted copy constructor/operator - I wouldn't consider that blowing up in my face.