Reputation: 3875
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?
Upvotes: 2
Views: 134
Reputation: 18117
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 &);
};
Upvotes: 9
Reputation: 3903
Separate the classes into separate files and have each reference the other in their respective header files.
Upvotes: 0