Assignment Operator

Hello !! I'm coding an ADT for set.
template <typename elem>
class Set
{
public:
Set();
~Set();
void add(const elem & e);
int length();
bool exist(const elem & e) ;
void union(Conjunto<elem> & conj2);
elem getelem(int pos);
Set(const Set<elem> & other);
Set<elem> & operator=(const Set<elem> & other);

private:
vector<elem> conj;

Does anybody know how to make the assignment operator ?
I think it goes a little somehting like this, but i don't know what I'm supposed to do in the middle...

template<typename elem>
Set<elem> & Set<elem>::operator=(const Set<elem> & other)
{
if(this != &other)
{
this->~Set();
{

}

}
return *this;
}

Thank you.
assuming the types provided to your template class can already be assigned normally, you might not have to do too much...

its possibly as simple as *this = other;

Assuming that your set only contains a std::vector, you do not need to implement the assignment operators. Default them, or use the implicitly defined ones.

In most cases you should follow the rule of three (five, since C++11):
https://en.wikipedia.org/wiki/Rule_of_three_(C%2B%2B_programming)
oh, and union is a keyword. this might cause issues.
Topic archived. No new replies allowed.