开发者

C++: Operator matches across classes

开发者 https://www.devze.com 2022-12-20 19:19 出处:网络
I\'m trying to do the following operation: R3MeshHalfEdge *tmp_edge = half_edge; R3Vector *tmp_vector = new R3Vector(R3zero_vector);

I'm trying to do the following operation:

  R3MeshHalfEdge *tmp_edge = half_edge;
  R3Vector *tmp_vector = new R3Vector(R3zero_vector);

  do
  {
    **tmp_vector += tmp_edge->face->plane.Normal();**
    tmp_edge = tmp_edge->opposite->next;
  }while(tmp_edge != half_edge);

However, the compiler gives me the following error:

R3Mesh.cpp: In member function ‘void R3MeshVertex::UpdateNormal()’:
R3Mesh.cpp:1291: error: no match for ‘operator+=’ in ‘tmp_vector += tmp_edge->R3MeshHalfEdge::face->R3MeshFace::plane.R3Plane::Normal()’

HalfEdge has the following structure:

class R3MeshHalfEdge {
  public:
    // Constructors
    R3MeshHalfEdge(R3MeshVertex* vertex, R3MeshFace* face);

    R3MeshVertex *vertex;
    R3MeshFace *face;
    R3MeshHalfEdge *opposite;
    R3MeshHalfEdge *next;
    int id;
};

Face has the following structure:

class R3MeshFace {
  public:
    // Constructors
    R3MeshFace(void);
    R3MeshFace(const R3MeshFace& face);
    R3MeshFace(const vector <R3MeshVertex *>& vertices);

    // Property functions
    double Area(void) const;

    // Data
    vector<R3MeshVertex *> vertices;
    R3Plane plane;
    R3MeshHalfEdge *half_edge;
    int id;
};

Vector has the following public operation defined in the class:

class R3Vector {
 public:
  R3Vector& operator+=(const R3Vector& vector);
}

It is implemented as such:

R3Vector& R3Vector::
operator+=(const R3Vector& vector)
{
  // Add vector to this 
  v[0] += vector.v[0];
  v[1] += vector.v[1];
  v[2] += vector.v[2];
  return *this;
}

I don't understand why the compiler is giving the error.

Edit: I forgot to include the Normal() definition for R3Plane:

class R3Plane{
  public:
    const R3Vector& Normal(void) con开发者_如何学Gost;
}


Looks like you added two asterisks before and after the offending line.

  R3Vector *tmp_vector = new R3Vector(R3zero_vector);

  do
  {
    **tmp_vector += tmp_edge->face->plane.Normal();**

Supposing you added two, and not one, at the beginning of the line, you had

    tmp_vector += tmp_edge->face->plane.Normal();

and tmp_vector is a pointer so you want

    *tmp_vector += tmp_edge->face->plane.Normal();
0

精彩评论

暂无评论...
验证码 换一张
取 消