Click to See Complete Forum and Search --> : std::vector<VARIANT> varVect


Emanuil Achim
May 27th, 1999, 08:59 AM
Hi all !

I kannot do a VARIANT (or better _variant_t) vector. This code:
#include &lt;vector&gt;
typedef std::vector&lt;VARIANT&gt; VariantVECTOR;

class MyClass
{
public:
MyClass(){;}
virtual ~MyClass(){;}

private:
VariantVECTOR myVarVect;
};

gives this compiler error:

C:\Programme\DevStudio\VC\INCLUDE\xutility(45) : error C2678: binary '&lt;' : no operator defined which takes a left-hand operand of type 'const struct tagVARIANT' (or there is no acceptable conversion)

Please help !

Thanks in advance !

Emanuil Achim

Franky Braem
May 27th, 1999, 09:12 AM
I think this is because VARIANT hasn't got a copy constructor. You can avoid this by making a vector of pointers to a VARIANT (VARIANT*).

Dave Lorde
May 27th, 1999, 10:02 AM
Subject: Re: std::vector&lt;VARIANT&gt; varVect

That code should be OK - it works in VC++6.0 SP3. What version of VC++ are you using, and what service packs?

It's complaining that there is no operator &lt;() (less than) for VARIANT). You should expect to get this error if you use sorting or comparison algorithms, because they generally require the contained object to have an operator &lt; () defined, and VARIANT does not (you could provide one, but it wouldn't be easy, as VARIANT can 'be' so many types!).

If I remember right, MSVC++ 5.0 had some oddities in the STL containers where they incorrectly required more comparison operators than they should, so maybe that's the problem...

Using VARIANT pointers is a reasonable work-around, though.

Dave