Multipurpose *

I’m a little confused about the use of the * in the Ulog.
Wasn’t it used as a converting operator in the Obstacle assault course for converting Fstring into string as well?

FString MyString = “MyStringValue”;
UE_LOG…TEXT("%s is moving", *MyStringValue);

Are there a lot of these multipurpose operators?

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 *.

To clarify what Dan said - FString overloads the ‘*’ operator which returns a pointer to the internal character array.

It can be a little confusing at first because normally something like *MyPtr reads as a dereference of the pointer variable, which is a standard C/C++ function (as opposed to an overloaded operator in the FString case).

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms