如何在c ++中声明类之前使用它?

Tib*_*ibi 2 c++ class operator-overloading

我试图通过重载'='运算符为两个类创建一些转换函数.这是一些代码:

class Vertex {
public:
    int X, Y;
        // .......
    Vertex& operator= (const VertexF &);   // ERROR, VertexF is not declared
};

class VertexF {
public:
    float X, Y;
        // ......
    VertexF& operator= (const Vertex &);
};
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

Mey*_*sam 9

使用前瞻声明:

class VertexF; // forward declaration of VertexF

class Vertex {
public:
    int X, Y;
        // .......
    Vertex& operator= (const VertexF &);   // ERROR, VertexF is not declared
};

class VertexF {
public:
    float X, Y;
        // ......
    VertexF& operator= (const Vertex &);
};
Run Code Online (Sandbox Code Playgroud)