D
dd
Hello!
I have following class (and its work fine):
#include <set>
#include <algorithm>
#include <iostream>
using namespace std;
class mySet: public set<char> {
public:
mySet(): set<char>() {}
template <class Iterator>
mySet(Iterator first,Iterator last): set<char>(first,last) {} /
friend ostream& operator<<(ostream &out, const mySet &X);
mySet& operator+(mySet &X);
};
ostream& operator<<(ostream &out, const mySet &X) {
out<<"{";
for (set<char>::iterator i=X.begin();i!=X.end();i++) {
if (i!=X.begin()) out<<", ";
out<<*i;
}
out<<"}";
return out;
}
mySet& mySet:perator+(mySet &X) {
mySet returnValue;
set_union(this->begin(),this-
}
It is a container set<char> with overloaded operators: << and +. Now I
would like to modify above code to create class template with
parameter T - a typ of elements of the set. I tried following code
(and it didn't work):
<cpp>
template <class T>
class mySet: public set<T> {
public:
mySet(): set<T>() {}
template <class Iterator>
mySet(Iterator first,Iterator last): set<T>(first,last) {} /
friend ostream& operator<<(ostream &out, const mySet<T> &X);
mySet<T>& operator+(mySet<T> &X);
};
template <class T>
ostream& operator<<(ostream &out, const mySet<T> &X) {
out<<"{";
for (set<char>::iterator i=X.begin();i!=X.end();i++) {
if (i!=X.begin()) out<<", ";
out<<*i;
}
out<<"}";
return out;
}
template <class T>
mySet<T>& mySet<T>:perator+(mySet<T> &X) {
}
</cpp>
How to achieve what I would like to achieve? Where I made mistakes? I
would be approciated for any help in this subject.
I have following class (and its work fine):
#include <set>
#include <algorithm>
#include <iostream>
using namespace std;
class mySet: public set<char> {
public:
mySet(): set<char>() {}
template <class Iterator>
mySet(Iterator first,Iterator last): set<char>(first,last) {} /
friend ostream& operator<<(ostream &out, const mySet &X);
mySet& operator+(mySet &X);
};
ostream& operator<<(ostream &out, const mySet &X) {
out<<"{";
for (set<char>::iterator i=X.begin();i!=X.end();i++) {
if (i!=X.begin()) out<<", ";
out<<*i;
}
out<<"}";
return out;
}
mySet& mySet:perator+(mySet &X) {
mySet returnValue;
set_union(this->begin(),this-
return returnValue;end(),X.begin(),X.end(),inserter(returnValue,returnValue.end()));
}
It is a container set<char> with overloaded operators: << and +. Now I
would like to modify above code to create class template with
parameter T - a typ of elements of the set. I tried following code
(and it didn't work):
<cpp>
template <class T>
class mySet: public set<T> {
public:
mySet(): set<T>() {}
template <class Iterator>
mySet(Iterator first,Iterator last): set<T>(first,last) {} /
friend ostream& operator<<(ostream &out, const mySet<T> &X);
mySet<T>& operator+(mySet<T> &X);
};
template <class T>
ostream& operator<<(ostream &out, const mySet<T> &X) {
out<<"{";
for (set<char>::iterator i=X.begin();i!=X.end();i++) {
if (i!=X.begin()) out<<", ";
out<<*i;
}
out<<"}";
return out;
}
template <class T>
mySet<T>& mySet<T>:perator+(mySet<T> &X) {
return returnValue;mySet said:end(),X.begin(),X.end(),inserter(returnValue,returnValue.end()));
}
</cpp>
How to achieve what I would like to achieve? Where I made mistakes? I
would be approciated for any help in this subject.