I know that this question has been asked before, and I red all the answers but I didn't find something that helped me. Hopefully you can ! So, I have a class named Vecteur which has two attributes: dimension (size of the table) and the table of values. And in the copy constructor when I try to copy the values of the Vecteur &v to the values of 'this' it gives me an error, and I don't know why because I think that I overloaded the [] operator ! (When I was trying to figure it out I put this->t[i] = v.t[i] and it worked ! but i found it weird because t is private).
Vecteur.h
#ifndef VECTEUR_H
#define VECTEUR_H
#include "typedef.h"
class Vecteur
{
public:
Vecteur(int);
Vecteur(const Vecteur&);
~Vecteur();
scal& operator[](int);
protected:
private:
int dim;
scal *t;
};
#endif // VECTEUR_H
Vecteur.cpp
#include "Vecteur.h"
#include "typedef.h"
Vecteur::Vecteur(int dim)
{
this->dim = dim;
t = new scal[dim];
}
Vecteur::~Vecteur()
{
delete[] t;
}
Vecteur::Vecteur(const Vecteur &v)
{
for(int i=0; i<dim; i++){
t[i] = v[i];//The error
}
}
scal& Vecteur::operator[](int i){
return t[i];
}