#include <iostream>
#include <cstdlib>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

template <class T>
class Set
{
public:
    T *p;       // change
    int n;
    Set(){ p=nullptr; n=0; 
    };
    Set(int n)
    {
        this->n = n;
        p = new T[n];   // change 
    }
    ~Set()
    {
      if(p) delete []p; 
    }
    void setValues(T k[],int l) // change signature
    {
    	if (n!=l) {          // if the size is the same, we'll reuse p, if not:
        	delete[] p;            // avoid the memory to leek 
        	p= new T[l];           // start with a fresh memory 
        	n = l;                 // define new length
    	}
        for (int i=0; i<l; i++) 
            p[i]=k[i];				// copy array elements one by one 
    }
    void add(T k)
    {
        auto p1 = p;    // improvement
        p = new T[n+1];
        //p = p1;    nooooooooo !!
		for (int i=0; i<n; i++)
			p[i]=p1[i]; 
        delete []p1; 	// no more leaking
      
        p[n] = k;
        n++;
    }
    void remove(T k)
    {
        //int l =0;     
        //auto p1 = p;      // no need to reallocateimprovement
        //p = new T[n-1];
        int removed=0; 
        for(int i=0,j=0;i<n;i++)
            if(p[i]!=k) 
            {
            	if (i!=j) 
                	p[j] = p[i];
                j++; 
            }
            else removed++;
        n=n-removed; 
    }
    void operator+(Set s)
    {
        for(int i=0;i<n;i++)
            p[i]+=s.p[i];
    }
    void operator-(Set s)
    {
        for(int i=0;i<n;i++)
            p[i]-=s.p[i];
    }
    void operator*(Set s)
    {
        for(int i=0;i<n;i++)
            p[i]*=s.p[i];
    }
    void show()
    {
        for(int i=0;i<n;i++)
            cout<<p[i]<<" | ";
    }
};
int main()
{
    Set<int> s1,s2;
    int arr[]={0,2,3,4,3,6};
    int n=6;
    float arr2[]={0.5,12.1,1.7,23.15};
    char arr3[]={'a','h','m','k','c','e'};
    s1.setValues(arr,n); // <------------- here is error;
    s1.add(5);
    s1.remove(3);
    s1.show();

}