Topic: Template instantiation with local types.
Author: bdjo@club-internet.fr (Brahim Djoudi)
Date: 1996/10/21 Raw View
Laurent D. Hasson wrote :
>I tried to do something, which i thought was perfectly OK:
> void Func(void)
> { typedef struct { ...} TotoStruct;
> Vector<TotoStruct> Toto;
>
> .....
> }
>
> Basically, my 2 compilers (BC++, VC++) refuses that piece of code, saying
>that it is illegal to instantiate templates local types!! I tried to think
>about it, for a long time, but i could not find a reason why this would be....
>Am i doing something wrong?
Hello.
I have tested you sample code with my C++ compiler (CodeWarrior 9 for
Macintosh). It has been compiled and linked without error message or
warning. Execution gives expected outcomes.
Conclusion :
I think that the problem is within the compiler and not due to language.
The compiler has probably an algorithm for naming class template not smart
enough to tackle to this context.
Regards.
{ Brahim }
Cordially.
Brahim Djoudi
GIAT Industries
155, av. de Grande-Bretagne
31000 Toulouse
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: ldh@interlog.com (Laurent D. Hasson)
Date: 1996/10/18 Raw View
I tried to do something, which i thought was perfectly OK:
void Func(void)
{ typedef struct { ...} TotoStruct;
Vector<TotoStruct> Toto;
.....
}
Basically, my 2 compilers (BC++, VC++) refuses that piece of code, saying
that it is illegal to instantiate templates local types!! I tried to think
about it, for a long time, but i could not find a reason why this would be....
Am i doing something wrong?
Thanks,
Laurent.
PS: Email greatly appreciated.
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: vandevod@cs.rpi.edu (David Vandevoorde)
Date: 1996/10/19 Raw View
>>>>> "LH" == Laurent D Hasson <ldh@interlog.com> writes:
[...]
LH> Basically, my 2 compilers (BC++, VC++) refuses that piece of code, saying
LH> that it is illegal to instantiate templates local types!! I tried to think
LH> about it, for a long time, but i could not find a reason why this would
LH be....
LH> Am i doing something wrong?
I think so (like your compilers said). I believe the concept of `point
of instantiation' may have changed a few times in the last year (not
positive), but I also think it has always been a point in `namespace
(or global) scope'... in that scope, your local type does not exist.
Daveed
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: fwai@armltd.co.uk (Francis Wai)
Date: 1996/10/21 Raw View
vandevod@cs.rpi.edu (David Vandevoorde) writes:
>>>>>> "LH" == Laurent D Hasson <ldh@interlog.com> writes:
>[...]
>LH> Basically, my 2 compilers (BC++, VC++) refuses that piece of code, saying
>LH> that it is illegal to instantiate templates local types!! I tried to think
>LH> about it, for a long time, but i could not find a reason why this would
>LH be....
>LH> Am i doing something wrong?
>I think so (like your compilers said). I believe the concept of `point
>of instantiation' may have changed a few times in the last year (not
>positive), but I also think it has always been a point in `namespace
>(or global) scope'... in that scope, your local type does not exist.
Err ...
>From 14.8 clause 4, the DWP (Oct-95) said,
4 Nor is a local type or a type with no linkage name an acceptable tem
plate-argument. [Example:
void f()
{
struct S { /* ... */ };
X<S,p> x3; // error: local type used as template-argument
}
--end example]
So, it would seem the real reason for refusing this is in constructing
the name for the specialized instance, not that it can't. I guess this
is the same reason for refusing string literals. But why not?
--Francis
>[ 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 ]
>[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
>[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
>[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: Alexandre Oliva <oliva@dcc.unicamp.br>
Date: 1996/10/21 Raw View
Laurent D Hasson writes:
[code snippet removed]
> Basically, my 2 compilers (BC++, VC++) refuses that piece of code,
> saying that it is illegal to instantiate templates local types!! I
> tried to think about it, for a long time, but i could not find a
> reason why this would be.... Am i doing something wrong?
Unfortunately, local types cannot be used as template arguments, as of
Sept 96 DWP [temp.arg #9]. Local types are types declared inside a
function body, by the way.
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br
Universidade Estadual de Campinas, SP, Brasil
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]