我需要帮助来使用自定义 c++ 类来管理 3D 位置来查找问题。这是该课程的相关代码
Punto operator+(Punto p){
return Punto(this->x + p.x, this->y + p.y, this->z + p.z);
}
Punto operator+(Punto *p){
return Punto(this->x + p->x, this->y + p->y, this->z + p->z);
}
Punto operator-(Punto p){
return Punto(this->x - p.x, this->y - p.y, this->z - p.z);
}
Punto operator-(Punto *p){
return Punto(this->x - p->x, this->y - p->y, this->z - p->z);
}
Punto *operator=(Punto p){
this->x = p.x;
this->y = p.y;
this->z = p.z;
return this;
}
Punto *operator=(Punto *p){
this->x = p->x;
this->y = p->y;
this->z = p->z;
return this;
}
我在这里使用它是这样的:
p = fem->elementoFrontera[i]->nodo[0] - fem->elementoFrontera[i]->nodo[1];
nodo[i] 是一个 Punto*,它编译得很好,但是当我尝试这样做时:
p = fem->elementoFrontera[i]->nodo[0] + fem->elementoFrontera[i]->nodo[1];
编译器说:
在成员函数
void mdTOT::pintarElementosFrontera()': error: invalid operands of types
Punto*' 和Punto*' to binary
operator+'