关于Boost::multi_index_container,错误c3849,绑定到int有什么问题
Again about Boost::multi_index_container, error c3849, what is wrong with binding to an int?
我有下面的代码,但"int age"似乎有问题,代码如下:
struct MyStruct
{
char* firstName;
char* secondName;
int age;
};
typedef composite_key
<MyStruct*,
BOOST_MULTI_INDEX_MEMBER(MyStruct, char*, firstName),
BOOST_MULTI_INDEX_MEMBER(MyStruct, char*, secondName),
BOOST_MULTI_INDEX_MEMBER(MyStruct, int, age)
> comp_key;
struct CompareLess
{ // functor for operator<=
static inline int compare(const char* left, const char* right)
{
return strcmp(left, right);
}
inline bool operator()(const char* left, const char* right) const
{ // apply operator<= to operands
return compare(left, right)<0;
}
static inline int compare(const MyStruct* myStruct1, const MyStruct* myStruct2)
{
int result= compare(myStruct1->firstName, myStruct2->firstName);
if(result!=0)
return result;
else
{
return compare(myStruct2->secondName, myStruct2->secondName);
}
}
inline bool operator()(const MyStruct* myStruct1, const MyStruct* myStruct2)
{
return compare(myStruct1, myStruct2)<0;
}
};
typedef multi_index_container
<
MyStruct*,
indexed_by
<
ordered_unique
<
comp_key,
/*CompareLess*/
composite_key_compare
<
CompareLess,
CompareLess,
std::less<int>
>
>
>
> MyContainer;
boost::ptr_vector<MyStruct> vec;
MyStruct* struct1=new MyStruct();
struct1->firstName="Michael";
struct1->secondName="Mike";
struct1->age=20;
vec.push_back(struct1);
MyContainer myContainer;
myContainer.insert(struct1);
char* first="Michael";
char* second="Mike";
string michael="Michael";
auto it=myContainer.find(boost::make_tuple(michael.c_str(), (const char*)second,20);
if(it!=myContainer.end())
cout << (*it)->age << endl;
问题出在"(boost::make_tuple(michael.c_str(),(constchar*)second),20)"上,它似乎无法接受"20"。详细错误如下:
C: \boost_1_52\boost/multi_index/composite_key.hpp(381):错误C3849:对类型为"int"的表达式的函数样式调用将丢失所有3个可用运算符重载的const和/或volatile限定符1> C:\boost_1_52\boost/multi_index/composite_key.hpp(380
有办法解决这个问题吗?
在修复了一个微不足道的语法错误(缺少括号)并添加了#include
等之后,事情就在这里工作了(MSVC 2012.)
相关文章:
- 向量 <int> a {N, 0} 和 int arr a[N] = {0} 的时间复杂度有什么区别
- "类模板示例<int>;"语句对 C++11 是什么意思?
- int数据类型的指针指向的是什么,如果是一个类的私有数据成员,我们创建了该类的两个对象?
- 是什么导致了这种使用三进制而不是短整型的有符号int到无符号int转换
- 关于int :0有什么特别之处在C++
- C++ 未初始化的本地(非全局)int 数组中的元素类型到底是什么?
- ((int) a) 和 (int(a)) 之间的区别是什么?
- 在 C 和 C++ 中作为函数参数,int **a 和 int a[][] 之间有什么确切的区别
- map<string, int> m= {}; 在C++中是什么意思?
- 有什么方法可以使用 int 变量来完成组件名称吗?
- int x_ 和 int x 在C++中有什么区别
- 行 - " vector<int> used(adj.size(), 0); "是什么意思?
- int** a = new int*[n]();这个函数有什么作用?
- *(int*)&data[18]在这段代码中实际上做了什么?
- 无符号长整型和无符号 int 之间有什么区别,这 2 种类型应该如何在 c# 中封送?
- 使输出流式处理运算符适用于 boost::variant<std::vector<int>、int、double 的正确方法是什么>
- "new int * **[10]"做什么?
- 什么是int(*)[]类型
- 什么是变量均值'int border = borderType & ~BORDER_ISOLATED'?
- 代码中的"vector<<int>vector>&index"是什么意思?