#include <vector>
#include <algorithm>
#include <iostream>
class myClass
{
int a;
};
void indexfinder (std::vector<myClass>& vec1, myClass& _key)
{
auto i = std::find(vec1.begin(), vec1.end(), _key);
//if it's found
if (i != vec1.end())
{
int k = i - vec1.begin();
std::cout << k;
}
//if it's not found
else
std::cout << -1;
}
int main()
{
myClass abc1;
myClass abc2;
myClass abc3;
std::vector<myClass>vec1 {abc1, abc2, abc3};
indexfinder(vec1,abc3);
}
I tried this without class, just with integers and it was working. This code is giving a lot of errors with class objects. Especially says there's no operator== for this type or smth.