Taking in a pointer

So when we declare this method

void SetBarrelReference(UStaticMeshComponent* BarrelToSet);

are we creating the BarrelToSet-pointer at this time?

What exactly is happening when we take in parameters in our methods like this? Somehow I have come to this point in the course and not understand this.

No, that’s not creating anything at that point. That would happen at the function call.

int square(int n)
{
    return n * n;
}

This just defines a function and nothing gets created until this is called.

int main()
{
    int number = 7;
    square(number);
}

Now here, square has been the argument of number and will be used to copy initialise n so n is a copy of number. This is known as passing-by-value.

void SetBarrelReference(UStaticMeshComponent* BarrelToSet);

is just declaring a function that will take a pointer to a UStaticMeshComponent

So when we call the function from blueprint, the pointer is created, and when we plug in the barrel reference node, it feeds this pointer the memory location of the barrel static mesh?

I think you might be confusing pointers. In this case there’s no additional memory allocation on the heap, the Barrel in the BP is basically a pointer, and passes it’s memory address to the function made in CPP.

Okay I think I got it :slight_smile:

Privacy & Terms