Topic: STL containers, local types and pointers to incomplete types


Author: ncm@nospam.cantrip.org (Nathan Myers)
Date: 1998/04/02
Raw View
Silvio Bierman<idfix@wxs.nl> wrote:
>Declaring a vector or list containing elements of a local type produces
>compiler errors:
>
>  class A {  enum B { a, b, c };   std::list<B> bs; };

In this case your compiler is right.  Local types have no
"linkage", and templates can only be specialized on types
that have linkage.

>Declaring a vector or list containing pointers to an incomplete type
>produces compiler errors:
>
>class A;
>class B {   std::list<A*> as; };

This is a broken compiler or library.  You can find a drop-in
replacement for VC++ (it works in DevStudio) by following this URL:
  http://www.cantrip.org/realworld.html#edison
It will also crash less, and support more modern language features.

You are far better off using the SGI STL than using the crippled
library that came with VC++.  Decent memory management and exception
safety are two of the more important improvements.

--
Nathan Myers
ncm@nospam.cantrip.org  http://www.cantrip.org/
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Gerhard Huebner" <ghuebner@lrt.mw.tu-muenchen.de>
Date: 1998/04/03
Raw View
>2
>Declaring a vector or list containing pointers to an incomplete type
>produces compiler errors:
>
>class A;
>
>class B
>{
>    std::list<A *> as;
>        ---compiler error: A is an incomplete type (so what?)
>};
>
>
>Do these examples represent non-conforming code or is the VC++ STL/C++
>implementation non-conforming.

I haven't tried problem 1 but problem 2 is a (known) bug of VC++5 and has
been fixed with Service Pack 3. Problem 2 is a real mess because it forces
you to include the definition of A, resulting in a coupling between the
class definitions that you wanted to avoid using the forward declaration. Be
careful, however, if you are using third-party libraries. They may have
trouble with the service pack. I crashed my O2 database system so I had to
go back to the original version without service pack.

Regards,

Dipl.-Phys. Gerhard Huebner        __
Institute of Astronautics          \ \____   "Not a plucky hero
--------------------------------===>--____>   until one reaches
Technische Universitaet Muenchen   /_/        the Great Wall"
Tel.: +49-89-289-16015, Fax: 16004
http://www.lrt.mw.tu-muenchen.de/personen/ghuebner/ghuebner.html
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Gerhard Huebner" <ghuebner@lrt.mw.tu-muenchen.de>
Date: 1998/04/03
Raw View
>>Declaring a vector or list containing pointers to an incomplete type
>>produces compiler errors:
>>
>>class A;
>>class B {   std::list<A*> as; };
>
>This is a broken compiler or library.  You can find a drop-in
>replacement for VC++ (it works in DevStudio) by following this URL:
>  http://www.cantrip.org/realworld.html#edison
>It will also crash less, and support more modern language features.
>
>You are far better off using the SGI STL than using the crippled
>library that came with VC++.  Decent memory management and exception
>safety are two of the more important improvements.

Unfortunately, the SGI STL also has disadvantages:

1.) No strings, only something like rope<char> that cannot fully replace
strings
2.) No string streams
3.) Most important of all: no numerical limits for processors other than
R4000.

The MS STL is rather complete and in the service pack, the problem with
pointers of undefined classes has been fixed.

Regards,

Dipl.-Phys. Gerhard Huebner        __
Institute of Astronautics          \ \____   "Not a plucky hero
--------------------------------===>--____>   until one reaches
Technische Universitaet Muenchen   /_/        the Great Wall"
Tel.: +49-89-289-16015, Fax: 16004
http://www.lrt.mw.tu-muenchen.de/personen/ghuebner/ghuebner.html
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: ncm@nospam.cantrip.org (Nathan Myers)
Date: 1998/04/04
Raw View
I'm sorry to respond to my own posting, but Valentin Bonnard pointed
out an error...

I wrote:
> Silvio Bierman<idfix@wxs.nl> wrote:
> >Declaring a vector or list containing elements of a local type produces
> >compiler errors:
> >
> >  class A {  enum B { a, b, c };   std::list<B> bs; };
>
> In this case your compiler is right.  Local types have no
> "linkage", and templates can only be specialized on types
> that have linkage.

My apologies; the type B above is not a locale type; it has linkage,
and its global name is A::B.  Mr. Bierman's code is correct, so again:

> This is a broken compiler or library.  You can find a drop-in
> replacement for VC++ (it works in DevStudio) by following this URL:
>   http://www.cantrip.org/realworld.html#edison
> It will also crash less, and support more modern language features.
>
> You are far better off using the SGI STL than using the crippled
> library that came with VC++.  Decent memory management and exception
> safety are two of the more important improvements.

--
Nathan Myers
ncm@nospam.cantrip.org  http://www.cantrip.org/
p.s. Mr. Huebner's suggestions may help as well; but others have
successfully adapted the SGI STL for use in DevStudio.
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Gerhard Huebner" <ghuebner@lrt.mw.tu-muenchen.de>
Date: 1998/04/06
Raw View
>p.s. Mr. Huebner's suggestions may help as well; but others have
>successfully adapted the SGI STL for use in DevStudio.

Does anyone have such a version of the SGI STL, where strings, string
streams and numerical limits for intel X86 processors have been implemented?

Dipl.-Phys. Gerhard Huebner        __
Institute of Astronautics          \ \____   "Not a plucky hero
--------------------------------===>--____>   until one reaches
Technische Universitaet Muenchen   /_/        the Great Wall"
Tel.: +49-89-289-16015, Fax: 16004
http://www.lrt.mw.tu-muenchen.de/personen/ghuebner/ghuebner.html




--Herd_of_Walrus_563_000--
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Silvio Bierman" <idfix@wxs.nl>
Date: 1998/04/02
Raw View
I am using VC++ 5.0 and have encountered two annoying things in using the
STL:

1
Declaring a vector or list containing elements of a local type produces
compiler errors:

class A
{
    enum B { a, b, c };
    std::list<B> bs;
        ---compiler error in instantiation of std::list: unknown type B
};


2
Declaring a vector or list containing pointers to an incomplete type
produces compiler errors:

class A;

class B
{
    std::list<A *> as;
        ---compiler error: A is an incomplete type (so what?)
};


Do these examples represent non-conforming code or is the VC++ STL/C++
implementation non-conforming.

Any opinions are welcome!


Silvio Bierman
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]