Error in C++ list::sort
Error in C++ list::sort
得到一堆错误,它们非常神秘
以下是所有相关代码:
// list::sort
#include <iostream>
#include <list>
#include <string>
#include <cctype>
#include "main.h"
using namespace std;
struct texture
{
int texture;
int ref;
};
bool compare_nocase (texture first, texture second)
{
if(first.texture < second.texture)
{
return true;
}
else
{
return false;
}
}
int main ()
{
list<texture> mylist;
list<texture>::iterator it;
texture moose;
moose.ref = 3;
moose.texture = 6;
texture moose2;
moose2.ref = 1;
moose2.texture = 3;
texture moose3;
moose3.ref = 2;
moose3.texture = 14;
mylist.push_back (moose);
mylist.push_back (moose2);
mylist.push_back (moose3);
cout << "before sort mylist contains:";
for (it=mylist.begin(); it!=mylist.end(); ++it)
cout << it->texture << endl;
cout << endl;
mylist.sort(compare_nocase);
cout << "after sort mylist contains:";
for (it=mylist.begin(); it!=mylist.end(); ++it)
cout << it->texture << endl;
cout << endl;
return 0;
}
我只是测试出STL排序函数,但我得到错误:
c:usersspanieldocumentsvisual studio 2010projectslistlistmain.cpp(12): error C2380: type(s) preceding 'texture' (constructor with return type, or illegal redefinition of current class-name?)
1>c:usersspanieldocumentsvisual studio 2010projectslistlistmain.cpp(18): error C2274: 'function-style cast' : illegal as right side of '.' operator
1>c:usersspanieldocumentsvisual studio 2010projectslistlistmain.cpp(18): error C2274: 'function-style cast' : illegal as right side of '.' operator
1>c:usersspanieldocumentsvisual studio 2010projectslistlistmain.cpp(35): error C2274: 'function-style cast' : illegal as right side of '.' operator
1>c:usersspanieldocumentsvisual studio 2010projectslistlistmain.cpp(39): error C2274: 'function-style cast' : illegal as right side of '.' operator
1>c:usersspanieldocumentsvisual studio 2010projectslistlistmain.cpp(43): error C2274: 'function-style cast' : illegal as right side of '.' operator
1>c:usersspanieldocumentsvisual studio 2010projectslistlistmain.cpp(51): error C2273: 'function-style cast' : illegal as right side of '->' operator
1>c:usersspanieldocumentsvisual studio 2010projectslistlistmain.cpp(59): error C2273: 'function-style cast' : illegal as right side of '->' operator
您有一个与struct
同名的struct
成员texture
。
显然VS 2010不喜欢这样,尽管GCC 4.1.2很好。
恐怕你不能这样做:
struct texture
{
v name is conflicted with struct name
int texture;
int ref;
};
相关文章:
- 使用std::multimap迭代器创建std::list
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- 为什么 std::unique 不调用 std::sort?
- 如何在 C 中正确使用 libiconv 使其不会报告"Arg list too long"?
- C++中带有List类的迭代器Segfault
- 使用"std::unordereded_map"映射到"std::list"对象
- GCC对可能有效的代码抛出init list生存期警告
- 使用std::list创建循环链表
- 如何使用list::sort()对STL列表对象进行排序,同时将自定义排序函数作为参数传递给list::排序
- 使用我自己的list.sort()逻辑,试图模仿其他来源,为什么我会因为看似正确的格式而出错
- 我可以让 std::list 按顺序插入新元素吗?或者必须使用std::sort
- 使用 std::sort 对 std::list 进行排序
- std::list.sort(谓词)编译器错误
- C++中的Merge Sort Singly Linked List在大输入时失败
- 使用std::list::sort会挂起我的程序
- 为什么 std::sort 在 std::list 上不起作用?
- Std:list.sort(),二元谓词
- 为什么只有std::list::sort()
- std::list.sort()的奇怪效率
- Error in C++ list::sort