Re: A strange problem about vector~
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. In fact, both A and vector could be incomplete and there would
still be nothing wrong with the typedef declaration. To demonstrate:
template <class T> class Vector;
class A;
typedef Vector<A> List; // OK
Of course, by the time that the program ever gets around to using the List
typedef to declare a List object then - certainly - Vector will have had to
have been completed by that point:
template <class T> class Vector;
class A;
typedef Vector<A> List;
template <class T> class Vector {};
List vList; // OK
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.
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. Therefore
there must be more to A's declaration than is known to us - and somewhere in
that part of A that was left out - is where the problem resides.
anyone who knows how to handle it ,thanks in advance
Depends on what you want to achieve. As it is, it can't be made to work.
With only the error message (and not the error) in evidence, I would say
that we don't really know for sure what the program is trying to do - and
therefore we know even less just how feasible are its plans.
Greg
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]