How do I force wxObject to be wxVariant?

I have a wxObject..but map, I want it to be convertible to wxVariant.

void MWDataViewTable::InitColumnValues(wxString targetcolumn,wxString sourcecolumn , std::map<wxObject,wxObject> srctargetvalue)
{
    wxVariant srcvalue;
    wxVariant tgtvalue;
    int srccolumnpos = GetColumnPosition(sourcecolumn);
    int tgtcolumnpos = GetColumnPosition(targetcolumn);
    int rows = m_rowdataList.size()-1;  //without header
    for(int i=0;i< rows;i++)
    {       
        GetValue(srcvalue,i,srccolumnpos);
        tgtvalue = (wxVariant)srctargetvalue[srcvalue] ;// typecasting
        SetValue(tgtvalue,i,tgtcolumnpos/*toggle-column*/);
    }

}

      

On the highlighted line, I do typecasting..but which gives me an error that says "Error 1 error C2678: binary '<': operator not found which takes left operand of type 'const wxObject'" this error goes to file xstddef.h ... I do not know why this is happening, or if I am mistakenly wrong. Help me please..!

+3


source to share


1 answer


In std::map

, key values are generally used to sort and uniquely identify the elements

.

In your code, both keys and values ​​are of type wxObject

. The class wxObject

doesn't seem to overload the less operator method (I have no idea what these wx objects are).

std::map

a method is required less operator

to perform the comparison required to sort the key values. Therefore, you must either pass your own comparison function to std :: map that would compare the two wxObjects.

The std :: map template container accepts a compare function as a third application.

template < class Key,                                     // map::key_type
           class T,                                       // map::mapped_type
           class Compare = less<Key>,                     // map::key_compare
           class Alloc = allocator<pair<const Key,T> >    // map::allocator_type
           > class map; 

      



Comparison is a binary predicate that will have the following definition in your case:

bool MyCompare( const wxObject& , const wxObject&)
{
  \\Compare logic that returns true or false
}

      

You can have your own map that uses this comparison method:

typedef std::map<wxObject,wxObject,&MyCompare> MyMap;
MyMap srctargetvalue;

      

+1


source







All Articles