How to create class template from class?

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::eek:perator+(mySet &X) {
mySet returnValue;
set_union(this->begin(),this-
end(),X.begin(),X.end(),inserter(returnValue,returnValue.end()));
return returnValue;
}

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>::eek:perator+(mySet<T> &X) {
mySet said:
end(),X.begin(),X.end(),inserter(returnValue,returnValue.end()));
return returnValue;
}
</cpp>

How to achieve what I would like to achieve? Where I made mistakes? I
would be approciated for any help in this subject.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top