David Webber wrote:
"Benry" <henrybg@gmail.com> wrote in message
news:1148998543.357718.323440@y43g2000cwc.googlegroups.com...
I'm using a vector object in my code.
(from MyType.h)
std::vector<CMyType> m_vMyType;
c:\program files\microsoft visual studio\vc98\include\xutility(19) :
error C2679: binary '=' : no operator defined which takes a right-hand
operand of type 'const class CMyType' (or there is no acceptable
conversion)
You need to supply an assignment operator - typically of the form
CMyType & CMyType::operator = ( const CMyType &x )
{
............
}
I do.
CMyType CMyType::operator=( CMyType &other ) {
//vector <int> v4( v2 );
std::vector <CString>::iterator v_Iter;
for ( v_Iter = other.vFields.begin( ) ; v_Iter != other.vFields.end( )
; v_Iter++ ){
this->vFields.push_back( *v_Iter );
}
this->sTableName = other.sTableName;
return *this;
}
c:\program files\microsoft visual studio\vc98\include\xmemory(34) :
error C2558: class 'CMyType' : no copy constructor available
and a copy constructor
CMyType::CMyType( const CMyType &x )
{
.........
}
I do that too.
CMyType:: CMyType( CMyType &rhs)
{
std::vector <CString>::iterator v_Iter;
for ( v_Iter = rhs.vFields.begin( ) ; v_Iter != rhs.vFields.end( ) ;
v_Iter++ ){
vFields.push_back( *v_Iter );
}
sTableName = rhs.sTableName;
}
Perhaps it's because I'm not using const? (five minute pause)...ok I
changed it to const, and now am having a problem with the vector
assignment loop. Perhaps if this is fixed? Could you recommend
something to fix the vector copying?
operator, and it works now. Thanks for the hint!!