I am trying to create some conversion functions for two classes by overloading the '=' operator. Here is some code:
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 &);
};
How can I make this work?
Use forward declaration:
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 &);
};
将类分隔为单独的文件,并使每个文件在其各自的头文件中引用另一个文件。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.