Topic: member access vs. templates?


Author: Marcus Barnes <marcus@nospam.multigen.com>
Date: 1998/08/07
Raw View
Hi All,

I was wondering if the following code snippet is legal. It compiles fine
under VC++ v5.0.
I don't think accessing B::N from class D should allowed as a template
parameter.

//BEGIN
#include <utility>

class B
{
//  protected:
        class N { friend class B; };

  public:
        N* newN () { return new N; }
};

class D : public B
{
        typedef std::pair< int, B::N* > type;    // ILLEGAL?
        type
        foo () { return type ( 1, newN() ); }

        std::pair< int, B::N* >    // ILLEGAL
        bar ()
        { return std::pair< int, B::N* > ( 2, newN() ); }
};
//END

Regards.

--
+ Marcus Barnes, Technical Staff        mailto:marcus@multigen.com +
+ Multigen Inc.                         http://www.multigen.com    +
+ 550 S. Winchester Blvd.               phoneto:1-408-367-2654     +
+ Suite 500 San Jose CA 95128           faxto:1-408-261-4103       +





[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Marcus Barnes <marcus@nospam.multigen.com>
Date: 1998/08/05
Raw View
Hi All,

This bit of code compiles without error on Microsoft Visual C++ v5.0. I
believe that it should be an error because the B::N is private. Is this
legal and "well formed"?

// BEGIN
// compiles without warning in VC++ v5.0 ... maybe illegal?

#include <utility>

class B
{
//protected:
 class N { friend class B; };
public:
 N* newN () { return new N; }
};

class D : public B
{
 typedef std::pair< int, B::N* > type; // LEGAL?
 type
 foo () { return type ( 1, newN() ); }

 std::pair< int, B::N* > // LEGAL?
 bar ()
 { return std::pair< int, B::N* > ( 2, newN() ); }
};

int
main ()
{
 return 0;
}
// END OF FILE

PS: I'm using std::pair<> because the issue only happens when the
private name is used as a template parameter. It's a compiler error
otherwise.

--
Regards,
Marcus


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]