POV-Ray : Newsgroups : povray.off-topic : Adventures with C++ : Re: An actual C++ question Server Time
29 Jul 2024 00:37:07 EDT (-0400)
  Re: An actual C++ question  
From: Warp
Date: 16 May 2013 11:27:04
Message: <5194fac8@news.povray.org>
scott <sco### [at] scottcom> wrote:
> > There "should" only ever be one instance of this class; I'd just like to
> > avoid the program exploding if somebody *does* copy that instance for
> > some reason. A shallow copy is acceptable.

> Is there a C++ equivalent to the C# static class? That would ensure at 
> compile-time that nobody tried to create an(other) instance.

You could use a namespace instead of a class. Private implementation can
then all go to the source file, away from the header file.

On the other hand, this limits where you can use this "pseudoclass" and
it could be difficult to maintain backwards compatibility if you ever
wanted to change it so that more than one instance could be created.

Of course you could have a class that only has static member functions...

-- 
                                                          - Warp


Post a reply to this message

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