小编And*_*rei的帖子

使用STL find_if()在对象指针向量中查找特定对象

我试图在对象指针的Vector中找到某个对象.让我们说这些是我的课程.

// Class.h
class Class{
public:
    int x;
    Class(int xx);
    bool operator==(const Class &other) const;
    bool operator<(const Class &other) const;
};

// Class.cpp
#include "Class.h"
Class::Class(int xx){
    x = xx;
}

bool Class::operator==(const Class &other) const {
    return (this->x == other.x);
}

bool Class::operator<(const Class &other) const {
    return (this->x < other.x);
}

// Main.cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include "Class.h"
using namespace std;

int main(){
    vector<Class*> set;
    Class *c1 = new Class(55);
    Class *c2 = new Class(34); …
Run Code Online (Sandbox Code Playgroud)

c++ stl

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

标签 统计

c++ ×1

stl ×1