The first compiles fine, because you can subtract pointers in C / C ++ but not add pointers. But in any case, it does not do what you need - it does not use your overloaded operator. Since your statements are defined in a class, you need to work with class instances, not pointers. So change something like
Punto p = *(fem->elementoFrontera[i]->nodo[0]) + *(fem->elementoFrontera[i]->nodo[1]);
Another thing is that you should use class references, not values, in the operator definition. For instance.
Punto& operator+(const Punto& p) {
EDIT. To simplify the code, you can create an access function, for example:
const Punto& NodoRef(int i, int j) { return *(fem->elementoFronteria[i]->Nodo[j]); }
and then your code becomes as clean as
p = NodoRef(i,0) + NodoRef(i,1);
NodoRef can be defined in your fem class or externally. Just make sure the fem object is alive in the area where you are using NodoRef.
source share