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)
我怎样才能做到这一点?
使用前瞻声明:
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)
| 归档时间: |
|
| 查看次数: |
97 次 |
| 最近记录: |