如何将 wxObject 类型转换为 wxVariant
How to typecast wxObject to wxVariant?
我有一个wxObject的地图。但我想将其类型转换为 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*/);
}
}
在突出显示的行中,我正在进行类型转换。.但这给了我一个错误,上面写着"错误 1 错误 C2678:二进制'<':找不到采用类型为'const wxObject'的左操作数的运算符"此错误出现在 xstddef.h 文件中。我不知道为什么会发生这种情况,或者我是否错误地键入了它。请帮忙..!
在std::map
中,key values are generally used to sort and uniquely identify the elements
.
在代码中,键和值都是wxObject
类型。wxObject
类似乎没有重载小于运算符的方法(我不知道这些wx对象是什么(。
std::map
需要一种less operator
方法来执行对键值进行排序所需的比较。因此,您应该将自己的比较函数传递给 std::map 来比较两个 wxObjects。
模板容器 std::map 将比较函数作为第三个条件。
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;
比较是一个二进制谓词,在您的情况下具有以下定义:
bool MyCompare( const wxObject& , const wxObject&)
{
\Compare logic that returns true or false
}
您可以拥有自己的地图,该地图将使用此比较方法:
typedef std::map<wxObject,wxObject,&MyCompare> MyMap;
MyMap srctargetvalue;
相关文章:
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- C++中的双指针类型转换
- 逐位操作的隐式类型转换
- 模板中的类型转换
- 在 C++(和 C)中进行类型转换时明显不一致
- 字符类型转换不兼容
- 将复杂的非基元C++数据类型转换为 Erlang/Elixir 格式,以使用 NIF 导出方法
- C++:用户定义的显式类型转换函数错误
- 将类指针类型转换为键时出错
- 通过引用传递参数时C++类型转换
- 在 C++ 中将一个模板类型的对象类型转换为另一个模板类型
- C++显式类型转换(C 样式强制转换)的强制表示法和static_cast的多种解释
- C++无效的函数类型转换
- 在将派生类指针类型转换为派生类指针后,从基类指针调用派生类函数
- 如何将Windows产品类型转换为名称?
- 通过构造函数方法输出的类到类类型转换是 5500 为什么不是 5555
- 事件系统:使用类型转换或联合进行继承
- 如何在参数中定义隐式类型转换的构造函数?
- 如何将 wxObject 类型转换为 wxVariant