 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Thomas Maeder Guest
|
Posted: Wed Sep 17, 2003 11:48 am Post subject: Re: typedef legal? |
|
|
André Pönitz <poenitz (AT) gmx (DOT) net> writes:
| Quote: | Is das folgende legal?
#include <list
class Foo;
typedef std::list
class Foo {};
int main()
{
FooList dummy;
}
Beachte das 'typedef' _vor_ der Definition von class Foo.
|
Nein.
17.4.3.6 sagt, "the effects are undefined [...] if an incomplete type is used
as a template argument when instantiating a template component." Gemeint ist
eine Template-Komponente der Standardbibliothek.
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
Christoph Rabel Guest
|
Posted: Wed Sep 17, 2003 12:04 pm Post subject: Re: typedef legal? |
|
|
Thomas Maeder wrote:
| Quote: | 17.4.3.6 sagt, "the effects are undefined [...] if an incomplete type is used
as a template argument when instantiating a template component." Gemeint ist
eine Template-Komponente der Standardbibliothek.
|
Durch das typedef wird aber IMHO das template nicht instantiiert. Daher
glaube ich nicht, das der Paragraph hier greift.
Man kann das ganze weiter reduzieren, denke ich:
class Foo;
typedef Foo X;
class Foo {}
int main() {
X x;
}
Wenn obiges legal ist, so dürfte auch das Beispiel von André legal sein.
Ich hab mal kurz die Definition von typedef überflogen, mir ist aber
nichts aufgefallen, das hier relevant ist.
comeau akzeptiert es, also ist es wahrscheinlich legal.
mfg
Christoph
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
Christoph Rabel Guest
|
Posted: Wed Sep 17, 2003 12:24 pm Post subject: Re: typedef legal? |
|
|
Christoph Rabel wrote:
| Quote: | Man kann das ganze weiter reduzieren, denke ich:
class Foo;
typedef Foo X;
class Foo {}
int main() {
X x;
}
Wenn obiges legal ist, so dürfte auch das Beispiel von André legal sein.
Ich hab mal kurz die Definition von typedef überflogen, mir ist aber
nichts aufgefallen, das hier relevant ist.
|
Im C Standard konnte ich eine Passage(Fussnote 109) finden, die ein
typedef auf einen incomplete Type explizit erlaubt.
Im C++ Standard, 3.9.7 wird ein Beispiel mit einem incomplete Array
gebracht.
Beim Beispiel zu 14.3.1 steht "[Note: a template type argument may be an
incomplete type (3.9). ]"
Ich schliesse aus diesen zwei Passagen, das der Code von André legal ist.
mfg
Christoph
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
Stefan Reuther Guest
|
Posted: Wed Sep 17, 2003 12:31 pm Post subject: Re: typedef legal? |
|
|
Hallo,
Christoph Rabel <odie (AT) hal9000 (DOT) vc-graz.ac.at> wrote:
[schnippeldi]
| Quote: | Im C Standard konnte ich eine Passage(Fussnote 109) finden, die ein
typedef auf einen incomplete Type explizit erlaubt.
Im C++ Standard, 3.9.7 wird ein Beispiel mit einem incomplete Array
gebracht.
Beim Beispiel zu 14.3.1 steht "[Note: a template type argument may be an
incomplete type (3.9). ]"
Ich schliesse aus diesen zwei Passagen, das der Code von André legal ist.
|
Es ist eine legale Verwendung der Programmiersprache C++.
Templates dürfen mit unvollständigen Typen instanziiert werden.
Es ist aber keine legale Verwendung der Standardbibliothek. Die
STL-Container dürfen nur mit vollständigen Typen instanziiert
werden.
Stefan
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
Markus Schaaf Guest
|
Posted: Wed Sep 17, 2003 12:50 pm Post subject: Re: typedef legal? |
|
|
"Stefan Reuther" <sr21 (AT) inf (DOT) tu-dresden.de> schrieb:
| Quote: | Es ist aber keine legale Verwendung der Standardbibliothek. Die
STL-Container dürfen nur mit vollständigen Typen instanziiert
werden.
|
Das invalidiert jedoch nicht seinen ersten Beitrag, wo er richtigerweise
darauf hinweist, daß ein »typedef« keine Instantiation darstellt. Eine
(implizite) Instantiation findet u.a. immer dann statt, wenn ein
"completely-defined object type" benötigt wird, z.B. hier:
struct foo : std::vector< bar > { /* ... */ );
Jedoch nicht hier:
std::vector< bar > * baz;
Und nicht hier:
typedef std::vector< bar > blah;
MfG
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|