小编use*_*868的帖子

C++在列表中对自定义对象进行排序

我在排序自定义类指针列表时遇到问题.我需要排序的类是事件.这些被分配一个随机时间,我需要按正确的顺序进行.

#include <list>

Class Event{
public: 
float time; // the value which I need to sort them by
int type; // to indicate which event i'm dealing with

Event(float tempTime, int tempType)
{
    time = tempTime;
    type = tempType; 
}


int main(){

std::list<Event*> EventList;
list<Event*>::iterator it;

.........
Run Code Online (Sandbox Code Playgroud)

如果你能帮我解决这个问题,我将不胜感激!我已经被困在这几个小时了.

谢谢!

c++ sorting events list object

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

c++ ×1

events ×1

list ×1

object ×1

sorting ×1