Re: A strange problem about vector~
Greg Herlihy wrote:
On 1/28/07 8:53 PM, in article 524ipiF1mu3vjU1@mid.uni-berlin.de, "Ulrich
Eckhardt" <doomster@knuut.de> wrote:
lfeiman888@gmail.com wrote:
class A
{
public:
typedef vector<A> List;
typedef List::iterator Iter;
};
According to the standard, vector<> can only be instantiated on complete
types. At the point you are using it, A is still an incomplete type.
The "List" typedef doesn't instantiate anything - so it could not be causing
a problem.
It's not causing a problem. It's the following typedef which
causes a problem.
[...]
In any event, the Standard Library's requirement that its components be
instantiated with complete types does not apply to this program. As is
evident from the error message, the program is using a third-party container
library (STLPort) and not the C++ Standard Library - and so is not governed
by its requirements.
As it happens, the STLPort is an implementation of the standard
library. And the second typedef above triggers the error (or
should---it's undefined behavior, but there's no reason not to
generate an error). The code doesn't compile with g++, for
example.
but when I compile with STLPort 5.1 under msvc 8.0
it give an error
D:\STLport\stlport\stl/type_traits.h(250) : error C2139: A: an
undefined class is not allowed as an argument to compiler intrinsic
type trait '__has_trivial_copy'
Well, the error message is slightly misleading, but basically it says that
A is not a fully defined class at the point it is used with something that
requires one.
It is the declaration of A that is misleading. After all, the declaration of
A that was posted contains no error like the one being reported.
The posted code is illegal. If we assume that it was preceded
by an "#include <vector>" and a "using namespace std;", it has
undefined behavior. G++ rejects it.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]