Article View: comp.sys.mac.programmer.codewarrior
Article #1120Re: unnamed namespaces in CW5.3
From: meeroh
Date: Sat, 27 Oct 2001 03:29
Date: Sat, 27 Oct 2001 03:29
76 lines
3284 bytes
3284 bytes
In article
<mjolnir_DELETE_-A4247B.03301526102001@east.usenetserver.com>,
Adin Hunter Baber <mjolnir_DELETE_@soltec.net> wrote:
>> Or you could, like I said, post your code, so we can give you a more
>> appropriate solution.
>
>namespace /*unnamed*/{
>
>struct SmartBase
> {
> mutable int counter;
>
> SmartBase(const int i)
> :counter(i)
> {}
> virtual ~SmartBase() {}
> };
>}// end namespace unnamed
>
>namespace Adin{
>
>template<class T>
>struct Smart : public SmartBase
> {
> T data;
>
> ~Smart() {}
>
> Smart()
> : SmartBase(0) {}
> Smart(const T &rt)
> : SmartBase(0), data(rt) {}
> Smart( T &rt)
> : SmartBase(0), data(rt) {}
>
> // other constructors
> };
>
>template<class T>
>class SmartPointer
> {
> public:
> SmartPointer(Smart<T> *rt);
> // lots of other stuff
> };
>}// end namespace Adin
>
>According to my design, there is not any real reason for some to have a
>SmartBase in existance outside of this file's scope.
You should make the SmartBase constructors protected and therefore
prevent people from instantiating SmartBase unless they derive from
SmartBase, but there is no way to prevent people from seeing the whole
declaration, since you need it in order to inherit from it.
Since you are putting things inside your own namespace, though, you may
want to consider putting SmartBase inside that namespace, or even better
inside a subnamespace. Somethine like Adin::Private::SmartBase. That
should be a strong enough hint that people should stay away from it, and
the protected ctors will prevent them from directly instantiating the
class.
hth
meeroh
>
>Basically, the code would be used this way:
>
>SmartPointer<someClass> myptr = new Smart<someClass>(parameters);
>
>If you are wondering, it is a smart pointer class that uses intrusive
>reference counting and handles polymorphism.
--
The contents of text files in a folder called "Random Signatures" in your Preferences folder are used as random signatures.
Technical Details
Message-ID:
<macdev-497EDD.23292026102001@senator-bedfellow.mit.edu>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!senator-bedfellow.mit.edu!dreaderd!not-for-mailReferences:
<mjolnir_DELETE_-8A9595.23380323102001@east.usenetserver.com> <macdev-854F03.01445224102001@senator-bedfellow.mit.edu> <mjolnir_DELETE_-3E19C3.18315324102001@east.usenetserver.com> <macdev-B6C0DF.19501624102001@senator-bedfellow.mit.edu> <mjolnir_DELETE_-A4247B.03301526102001@east.usenetserver.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10bcce,426dc3c68e8241c3 X-Google-Attributes: gid10bcce,public X-Google-Thread: f635e,426dc3c68e8241c3 X-Google-Attributes: gidf635e,public X-Google-ArrivalTime: 2001-10-26 20:29:26 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!senator-bedfellow.mit.edu!dreaderd!not-for-mail From: meeroh <macdev@meeroh.org> Newsgroups: comp.sys.mac.programmer.codewarrior,codewarrior.mac Mail-Copies-To: poster Subject: Re: unnamed namespaces in CW5.3 Organization: MIT References: <mjolnir_DELETE_-8A9595.23380323102001@east.usenetserver.com> <macdev-854F03.01445224102001@senator-bedfellow.mit.edu> <mjolnir_DELETE_-3E19C3.18315324102001@east.usenetserver.com> <macdev-B6C0DF.19501624102001@senator-bedfellow.mit.edu> <mjolnir_DELETE_-A4247B.03301526102001@east.usenetserver.com> User-Agent: MT-NewsWatcher/3.1 (PPC) Date: Fri, 26 Oct 2001 23:29:20 -0400 Message-ID: <macdev-497EDD.23292026102001@senator-bedfellow.mit.edu> Lines: 76 NNTP-Posting-Host: TITANIUM-48.MIT.EDU X-Trace: 1004153360 senator-bedfellow.mit.edu 1915 18.101.0.199