我正在尝试通过重载“=”运算符为两个类创建一些转换函数。这是一些代码:
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 &);
};
我怎样才能让它工作?
最佳答案
使用前向声明:
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 &);
};
关于c++ - 在 C++ 中声明类之前如何使用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9238906/