POV-Ray : Newsgroups : povray.off-topic : Adventures with C++ : Re: An actual C++ question Server Time
29 Jul 2024 00:33:13 EDT (-0400)
  Re: An actual C++ question  
From: Warp
Date: 15 May 2013 17:53:17
Message: <519403cd@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
>     class PrivateClass;

>     class MyClass
>     {
>         std::shared_ptr<PrivateClass> privateObject;
>     };

Oh, and take into account that if instances of MyClass are copied around,
the copies will share the one and same PrivateClass object. That will not
get deep-copied. (That's what the "shared ptr" means, actually.)

If you want to avoid MyClass being copied around, that can be disabled.
(Of course this restricts the ways in which the class can be used, so
it's always a compromise.)

Another possibility is to write a copy constructor and a copy assignment
operator that deep-copies the private object... It all depends on how
exactly you need MyClass to behave.

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.