set_union problem

My compiler says there is an error "instantiated from here" which I have no clue what it means. Can someone explain what is wrong with the coding?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  #include <iostream>
#include <deque>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <vector>
#include <map>
#include <functional>
using namespace std;
class B{int val;
public:
    B(int v):val(v){}
    int getV()const{return val;}bool operator < (const B & v)const{return val<v.val;}};
    ostream & operator <<(ostream & out, const B & v){out<<v.getV();return out;}
    template<class T>struct Out{
        ostream & out;
        Out(ostream & o):out(o){}
        void operator()(const T & val){out<<val<<" ";}
    };

int main(){
  
    B t1[]={3,2,4,1,5};
    int t2[]={5,6,8,2,1};
    vector<B>v1(10,0);
    sort(t1,t1+5);
    sort(t2,t2+5);
    set_union(t1,t1+5,t2,t2+5,v1.begin());   /// here is the error line
    for_each(v1.begin(),v1.end(), Out<B>(cout));cout<<endl;
    return 0;

}
> error "instantiated from here" which I have no clue what it means
then don't paraphrase it, that part of the message is just providing context.

$ g++ foo.cpp 2>&1 | grep error
error: no match for ‘operator<’ in ‘* __first2 < * __first1’ (operand types are ‘int’ and ‘B’)
so provide the comparison function.


Also, learn to indent.
Last edited on
Topic archived. No new replies allowed.