🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2979

Re: Nested template class definitions

#2979
From: Alan Griffiths
Date: Wed, 03 Jan 1996 15:59
104 lines
3717 bytes
I fear we're getting off topic, but there are a lot of programmers 
that will be thinking that the language implemented by Microsoft bears
some relationship to the standard.

In fact MSVC4 has quite a few problems with nested classes 
and templates (examples below).  (I don't think MS incorporated 
anything more recent than mid '94 - certainly not the public review 
draft ANSI produced.)

The public draft is also far from clear in some areas (e.g. tempates
and the interaction between namespace and templates).  In particular
I feel that the second example below should be valid (without the
MSVC fix), but finding clear statements justifying this is beyond me.


Example 1:

    #include <vector.h>

    #if defined(_MSC_VER) && (_MSC_VER <= 1000)
        template<class T> class Class_Value {
            public:
                Class_Value() {}
                Class_Value(const T& t) : v(t) {}

            private:
                T v;
         };
    #endif

    template<class T> class Class {
        public:

        #if !(defined(_MSC_VER) && (_MSC_VER <= 1000))
            class Value {
                public:
                    Value() {}
                    Value(const T& t) : v(t) {}

                private:
                    T v;
            };
        #else
            typedef ::Class_Value<T> Value;
        #endif

            Value f(const T& t) const { return t; }

        private:

            // MS resolves this with incorrect name binding
            // - see above conditionals
            vector<Value> array;
    };

    typedef  Class<int> IntClass;

    int main() {
        IntClass c;
        IntClass::Value v = c.f(0);
        return 0;
    }

Example 2:

    #include <vector.h>

    namespace MyNameSpace {
        template<class T> class Element {
            public: T t;
        };

        template<class T> class Container {
            public: vector<MyNameSpace::Element<T> > array;
        };
    }
                    
    #if defined(_MSC_VER) && (_MSC_VER <= 1000)
        using MyNameSpace::Element<int>;
    #endif

    typedef MyNameSpace::Element<int>   MyIntElement;
    typedef MyNameSpace::Container<int> MyIntContainer;

    int main() {
        MyIntContainer collection;
        MyIntElement   e;
        e.t = 1;

        collection.array.push_back(e);

        return 0;
    }

--
Alan Griffiths               | Also editor of: The ISDF Newsletter
Senior Systems Consultant,   | (An Association of C and C++ Users publication)
CCN Group Limited.           | (ISDF editor  : isdf@octopull.demon.co.uk)
(agriffiths@ma.ccngroup.com) | (For ACCU see : http://bach.cis.temple.edu/accu)

---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <864730614wnr@ma.ccngroup.com>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
References: <9600116.2625@mulga.cs.mu.OZ.AU> <4c525e$one@nnrp1.news.primenet.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 03 Jan 96 15:59:21 GMT
Approved: fjh@cs.mu.oz.au
From: Alan Griffiths <aGriffiths@ma.ccngroup.com>
Newsgroups: comp.std.c++
Subject: Re: Nested template class definitions
X-Original-Date: Wed, 03 Jan 1996 13:32:55 GMT
Organization: CCN Market Analysis
Message-ID: <864730614wnr@ma.ccngroup.com>
References: <9600116.2625@mulga.cs.mu.OZ.AU> <4c525e$one@nnrp1.news.primenet.com>
Reply-To: aGriffiths@ma.ccngroup.com
X-Broken-Date: Wednesday, Jan 03, 1996 13.32.55 GMT
X-Newsreader: Newswin Alpha 0.6
X-Mail2News-Path: devmaccn.demon.co.uk
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMOqn5+EDnX0m9pzZAQHzgAGAheYGrt9llWeAnHsINMgCjY8BeIbZYyBD
 paqAPli+si5Pdf5AEn+PIqJHuHGuqyqi
 =jcUw