I have little knowledge of C ++, I tried to declare the operator as follows:
struct Simple2D {
var x: Double! , y: Double!
func setS(x0:Double , y0:Double)->Simple2D {
return Simple2D(x: x0, y: y0)
}
func lenght(v: Simple2D)->Double {
return pythagorous2(v.x, b:v.y)
}
}
var tx = Simple2D(x: 2.0, y: 2.0)
prefix operator * {}
prefix func * (v: Simple2D)-> Double {
return tx.x*v.x + tx.y*v.y
}
this does not work, how do I call the functions from another file?
This original file in c++ :
ile Simple2D.h
template <typename T>
struct Simple2D
{
T x, y;
/
Simple2D <T>() {
x = y = 0;
}
/
Simple2D <T>(const T x0, const T y0) : x(x0), y(y0) {
}
/
void operator ()(const T x0, const T y0)
{
x= x0; y= y0;
}
/
bool operator ==(const Simple2D<T> &v) const;
/
Simple2D <T> operator -(const Simple2D <T> &v) const;
/
Simple2D <T> operator -(void) const;
}
file Simple2D.cpp
template <typename T>
bool Simple2D <T>::operator ==(const Simple2D <T> &v) const
{
return (is_equal(x,v.x) && is_equal(y,v.y));
}
template <typename T>
Simple2D <T> Simple2D <T>::operator -(void) const
{
return Simple2D <T>(-x,-y);
}
template <typename T>
Simple2D <T> Simple2D <T>::operator -(const Simple2D <T> &v) const
{
return Simple2D <T>(x-v.x, y-v.y);
}