Syntax confusion for constructor call and assignment

Hi,

I am very confused by the following assignment in this lecture:

FCollisionQueryParams QueryParams(FName(TEXT("")), false, GetOwner());

Initially to me this looked like a syntax error, especially because no variable assigment via = seems to have taken place.

I was expecting the following syntax instead and trying this works fine:

FCollisionQueryParams QueryParams = FCollisionQueryParams(FName(TEXT("")), false, GetOwner());

Is the form used in the lecture a shorthand syntax for this typical assignment + constructor call? I don’t recall seeing it explained in previous lectures.

I would appreciate any explanation or links to documentation or previous lectures that explains how this works.

Thanks!

The first is using direct initialisation the other should be a move construction (stackoverflow on move semantics).

There is no assignment in that, it’s an initialisation. @ben probably should have never used = for an initialisation and preferred {} since I can see how = can make things confusing whether initialisation or assignment is happening.

1 Like

@DanM can you suggest an insertion into the video at a particular time that would make this clearer for people?

Not really sure how to go about it unless you add a lecture somewhere in section 2 on the topic of the 3 different ways to initialise variables.

//c-like initialisation
std::string a = "a";
//constructor initialisation
std::string b("b");
//uniform initialisation
std::string c{ "c" }; //also the same as std::string c = { "c" }

And to say that you should prefer uniform initialsation, see also: this

Thanks a lot for the help here, appreciate it!

the time is 8:32

Privacy & Terms