public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* What's wrong with this class temlate's typedef?
@ 2008-07-23  9:22 Rob
  2008-07-30  5:11 ` Lawrence Crowl
  0 siblings, 1 reply; 2+ messages in thread
From: Rob @ 2008-07-23  9:22 UTC (permalink / raw)
  To: GCC help

Hi,

The following code snippet is a stripped down version of what I use in my code.
Last time I compiled this code is several years ago......I tried to compile it again
today with GCC 4.3.0 (20080428), but now I get an error message:

--------------------------------------------------------
template <typename T = double, unsigned int d = 3> class A { };

template <typename T = double> class B : public A<T, 4> {
    typedef A<T, 3> A;
};

int main () { B<double> *object; };
--------------------------------------------------------


Error message:
   4: error: declaration of ‘typedef class A<T, 3u> B<T>::A’
   1: error: changes meaning of ‘A’ from ‘class A<T, 3u>’

Here, I could use class "A" as a substitute for "A<T,3>" only within the class B.
That used to work in the past. Is there a way to get this compiled again without
having to change all the class names in the typedef?

Thank you.

Rob.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: What's wrong with this class temlate's typedef?
  2008-07-23  9:22 What's wrong with this class temlate's typedef? Rob
@ 2008-07-30  5:11 ` Lawrence Crowl
  0 siblings, 0 replies; 2+ messages in thread
From: Lawrence Crowl @ 2008-07-30  5:11 UTC (permalink / raw)
  To: Rob; +Cc: GCC help

On 7/22/08, Rob <spamrefuse@yahoo.com> wrote:
> The following code snippet is a stripped down version of what I use
> in my code.  Last time I compiled this code is several years ago......
> I tried to compile it again today with GCC 4.3.0 (20080428), but
> now I get an error message:
>
> --------------------------------------------------------
> template <typename T = double, unsigned int d = 3> class A { };
>
> template <typename T = double> class B : public A<T, 4> {
>    typedef A<T, 3> A;
> };
>
> int main () { B<double> *object; };
> --------------------------------------------------------
>
> Error message:
>   4: error: declaration of 'typedef class A<T, 3u> B<T>::A'
>   1: error: changes meaning of 'A' from 'class A<T, 3u>'
>
> Here, I could use class "A" as a substitute for "A<T,3>" only within
> the class B.  That used to work in the past.

The code has never been legal, but has worked because (1) the
compiler did not check and (2) the compiler processed declarations
in such a way that it did what you wanted.

> Is there a way to get this compiled again without having to change
> all the class names in the typedef?

Yes, qualify the definition of the typedef.

  typedef ::A<T, 3> A;

-- 
Lawrence Crowl

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-07-29 21:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-23  9:22 What's wrong with this class temlate's typedef? Rob
2008-07-30  5:11 ` Lawrence Crowl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).