I've been looking to see how to declare a method in a Python class that is the equivalent of how Java and C++ will take the class type as a parameter, as in a copy constructor method.
Java Class:
class Point {
protected float x;
protected float y;
public Point() {
this.x = 0.0f; this.y = 0.0f;
}
public Point( Point p ) {
this.x = p.x; this.y = p.y;
}
public boolean isEqual( Point p ) {
return this.x == p.x && this.y == p.y;
}
public void setValues( float x, float y ) {
this.x = x; this.y = y;
}
public void setValues( Point p ) {
this.x = p.x; this.y = p.y;
}
}
Here's the Python class I've go so far:
class Point:
def __init__(self):
self.x = 0.0;
self.y = 0.0;
def setValues( x, y ):
self.x = x
self.y = y
#def __init__( Point ): how to pass an instance of this class to copy the values?
#def isEquals( Point ): this would return True or False if the values are both equal.
#def setValues( Point ): how to pass an instance of Point?
I'm not familiar with Python so I'm not sure how to define a member function that would take it's class type as a parameter. What would the Python equivalent of a copy constructor, or the isEqual() method defined in the Java code?
Thanks.