Most operators are overloadable meaning you can define what it means for your type. This is how things you’ve already used work. For example
struct FVector
{
double X;
double Y;
double Z;
};
void Example()
{
FVector V1{ 1.0, 2.0, 3.0 };
FVector V2{ 10.0, 20.0, 30.0 };
V1 + V2 * 100.0;
}
This code won’t compile as FVector + FVector
nor FVector * double
have not been defined, only the built-in types already have defined meaning. Though each definition of those is straight forward and intuitive to implement.
FVector operator+(const FVector& Lhs, const FVector& Rhs)
{
return FVector{ Lhs.X + Rhs.X, Lhs.Y + Rhs.Y, Lhs.Z + Rhs.Z };
}
FVector operator*(const FVector& Vec, double Scale)
{
return FVector{ Vec.X * Scale, Vec.Y * Scale, Vec.Z * Scale };
}
Each definition relying on the definitions of the arithmetic operators for double
.
The same thing is with the case of FString and pointers regarding *
.