Topic: Does the standard mandate that this compiles/fails?


Author: Graeme Prentice <gp1@paradise.net.nz>
Date: Thu, 18 Apr 2002 16:21:36 GMT
Raw View
On Tue, 16 Apr 2002 16:57:30 GMT, Howard Gardner <usenet@hgardner.com>
wrote:

>//
>// I've got one compiler that likes this fine, and one that doesn't.
>// Is one right and the other wrong, or is it grey?
>//

Its illegal  - section 14.6.3

>
>template <class T> struct A
>{
>  void func(void);
>};
>
>template <class T> void A<T>::func(void)
>{
>  B b; // One compiler hates this line (B is not a type yet.)
>}
>
>class B{};
>
>void main(void)
>{
>  A<int> a;
>  a.func();
>}

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Graeme Prentice <gp1@paradise.net.nz>
Date: Thu, 18 Apr 2002 20:23:21 GMT
Raw View

[moderator  -  I accidentally hit send on my last post before I meant
to  - could you cancel it please ]


On Tue, 16 Apr 2002 16:57:30 GMT, Howard Gardner <usenet@hgardner.com>
wrote:

>//
>// I've got one compiler that likes this fine, and one that doesn't.
>// Is one right and the other wrong, or is it grey?
>//

Its illegal  - section 14.6.3  - names which don't depend on a
template type must be visible at the point they are used in the
definition of the template

<14.6.3>
1 Non-dependent names used in a template definition are found using
the usual name lookup and bound at the
point they are used.
<>


>
>template <class T> struct A
>{
>  void func(void);
>};
>
>template <class T> void A<T>::func(void)
>{
>  B b; // One compiler hates this line (B is not a type yet.)
>}
>
>class B{};
>
>void main(void)
>{
>  A<int> a;
>  a.func();
>}

Graeme


======================================= MODERATOR'S COMMENT:

Please refer to the newsgroup FAQ for instructions on what to do
when you hit "send" to soon, and for more information about
cancelling articles. Asking in a new posting cannot work.

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Howard Gardner <usenet@hgardner.com>
Date: Tue, 16 Apr 2002 16:57:30 GMT
Raw View
//
// I've got one compiler that likes this fine, and one that doesn't.
// Is one right and the other wrong, or is it grey?
//

template <class T> struct A
{
  void func(void);
};

template <class T> void A<T>::func(void)
{
  B b; // One compiler hates this line (B is not a type yet.)
}

class B{};

void main(void)
{
  A<int> a;
  a.func();
}

--
I <3 Comeau C++: http://www.comeaucomputing.com

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]