Hello---
I've written a class where I would like to overload the equal sign (= sign) operator so that I can return a double during an assignment. The following code snippet shows what I would like to do, but for some strange (probably small) reason, it does not seem to work.
Here is the main function in the entry class of the program:
int main()
{
Vertex v;
double testval = v; // error occurs here
return 0;
}
Here is the function in the Vertex.cpp file:
double Vertex::operator = (const Vertex &rhs)
{
value = 10.564;
return value;
}
Here is the code in the header file Vertex.h:
class Vertex
{
public:
Vertex();
double operator = (const Vertex &rhs);
private:
double value;
};
However, at compile-time, the compiler complains that:
cannot convert 'Vertex' to 'double' in initialization
Why can't the compiler convert 'Vertex' to double? What am I doing wrong here?