Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > standard conform typedef?

Reply
Thread Tools

standard conform typedef?

 
 
stip
Guest
Posts: n/a
 
      04-21-2011
template <typename T>
struct A
{
};

template <typename T>
struct B
{
typedef A<T> A;
};

int
main()
{
return 0;
}

Look at the reuse of "A".
IMHO this is legal. But gcc rejects it:
Declaration of ╗typedef struct A<T> B<T>::Aź

If it is not legal, can someone point me to the corresponding part of
the standard?

Best,
Alex
 
Reply With Quote
 
 
 
 
Qi
Guest
Posts: n/a
 
      04-21-2011
On 2011-4-21 16:31, stip wrote:

> Look at the reuse of "A".
> IMHO this is legal. But gcc rejects it:
> Declaration of ╗typedef struct A<T> B<T>::Aź
>
> If it is not legal, can someone point me to the corresponding part of
> the standard?


Chapter 14, item 5,

"A class template shall not have the same name as any other template,
class, function, object, enumeration,
enumerator, namespace, or type in the same scope (3.3), except as
specified in (14.5.4). Except that a function
template can be overloaded either by (non-template) functions with the
same name or by other function
templates with the same name (14.8.3), a template name declared in
namespace scope or in class scope
shall be unique in that scope."


--
WQ
 
Reply With Quote
 
 
 
 
Johannes Schaub
Guest
Posts: n/a
 
      04-21-2011
stip wrote:

> template <typename T>
> struct A
> {
> };
>
> template <typename T>
> struct B
> {
> typedef A<T> A;
> };
>
> int
> main()
> {
> return 0;
> }
>
> Look at the reuse of "A".
> IMHO this is legal. But gcc rejects it:
> Declaration of ┬╗typedef struct A<T> B<T>::A┬ź
>
> If it is not legal, can someone point me to the corresponding part of
> the standard?
>


This is ill-formed with no diagnostic required. Refer to
3.3.6[basic.scope.class]p1, subparagraph 2).


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is this program standard conform? Fumeur C Programming 25 01-22-2008 11:52 PM
Yet another generics question: Needs unchecked conversion to conform to ... Michel T. Java 14 01-18-2007 10:29 PM
Can Division Width Conform To Content X l e c t r i c HTML 3 02-16-2006 11:13 PM
Format of the initialization string does not conform to specification starting at index 5." andy ASP .Net 0 12-21-2004 10:38 PM
connection string exception : Format of the initialization string does not conform to specification starting at index 0 Gaurav ASP .Net 0 11-07-2003 10:24 AM



Advertisments