I'm getting this error when I try to compile my code.
I dont have any *
(pointers) and can't understand why im getting this.
Im working now with template
. You can check my code too see:
#include <iostream>
#include <cstdlib>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
template <class T>
class Set
{
public:
T **p;
int n;
Set(){
};
Set(int n)
{
this->n = n;
p = new T*[n];
}
~Set()
{
if(p) delete []p;
}
void setValues(T k,int l)
{
p = k;
n = l;
}
void add(T k)
{
T p1;
p1 = p;
p = new T[n+1];
p = p1;
p[n+1] = k;
n++;
}
void remove(T k)
{
T p1;
int l =0;
p1 = p;
p = new T[n-1];
for(int i=0;i<n;i++)
if(p1[i]!=k)
{
p[l] = p1[i];
l++;
n--;
}
}
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.show();
}
I'm getting error on this line s1.setValues(arr,n);
This is setValues()
method:
void setValues(T k,int l)
{
p = k;
n = l;
}
I had tried to avoid the error by using &
like that: s1.setValues(arr,&n)
and s1.setValues(arr,*n)
Also I tried to change it in method: void setValues(T k,int &l)
and void setValues(T k,int *l)
in class: public:
T **p;
int *n;
and public:
T **p;
int &n;
In my first version I have tried to use: s1.setValues(arr,6)
where 6
is the length of the array. But I was also getting the error;