我试图在对象指针的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)