Error Code C3867: non-standard syntax; use '&' to create a pointer to member

As I followed the lesson 124, I have encountered the error when I compiled the following code (which is in UGrabber::TickComponent member function:

if (Physicshandle->GrabComponentAtLocationWithRotation)
{
	// move the object that we're holding
	Physicshandle->SetTargetLocation(LineTraceEnd);
}

I have tried if &(Physicshandle->GrabComponentAtLocationWithRotation), but it did not work. Is there anyway to define address of member function of pointer?

GrabComponentAtLocationWithRotation is a function with () on the end and it takes in some stuff :slight_smile:

It should be something like the following…

auto HitResult = GetFirstPhysicsBodyInReach();
auto ComponentToGrab = HitResult.GetComponent();
auto ActorHit = HitResult.GetActor();

if (ActorHit)
{
	PhysicsHandle->GrabComponentAtLocationWithRotation(
		ComponentToGrab,
		NAME_None,
		ComponentToGrab->GetOwner()->GetActorLocation(),
		ComponentToGrab->GetOwner()->GetActorRotation()
	);
}

Hi, thanks for your reply. The problem I mentioned is actually in the UGrabber::TickComponent , not in UGrabber::Grab(), which is what you have stated. In the UGrabber::TickComponent, I will need to use function pointer to verify if the Physicshandle->GrabComponentAtLocationWithRotation existed without being a null pointer. Physicshandle->GrabComponentAtLocationWithRotation() will not help in this case as it is a function call, not pointer.
Here is the code for the UGrabber::TickComponent function:

void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	/// Get player view point this tick 
	FVector PlayerViewPointLocation;
	FRotator PlayerViewPointRotation;
	GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(
		OUT PlayerViewPointLocation,
		OUT PlayerViewPointRotation
	);

	FVector LineTraceEnd = PlayerViewPointLocation + PlayerViewPointRotation.Vector() * Reach;

	// if the physics handle is attached
	if (Physicshandle->GrabComponentAtLocationWithRotation)
	{
		// move the object that we're holding
		Physicshandle->SetTargetLocation(LineTraceEnd);
	}	
}

I’m confused by what you want. Are you simply wanting to check if GrabComponentAtLocationWithRotation returns null (aka is valid)? as in == nullptr.

GrabComponentAtLocationWithRotation is from UE and might not ever return null. There are things that UE cannot have null for the game to work so there’s no guarantee that it will ever return null possibly making it pointless.

Not everything needs a null check… otherwise the faster approach is to blanket the whole code to catch errors instead of putting ugly checks everywhere.

GrabComponentAtLocationWithRotation() only needs to be used once where I first specified.

in TickComponent it is…

if (PhysicsHandle->GrabbedComponent) {} // Do not use GrabComponentAtLocationWithRotation here.

I’m confused by what you want. Are you simply wanting to check if GrabComponentAtLocationWithRotation returns null (aka is valid)? as in == nullptr.

Yes. Was getting error of "non-standard syntax; use ‘&’ to create a pointer to member" and suspected that a pointer is needed which points to the function GrabComponentAtLocationWithRotation to verify the function’s existence.

The reason I used GrabComponentAtLocationWithRotation is because I have replaced every GrabComponent deprecated function with GrabComponentAtLocationWithRotation.
But after checking back the lesson, I realized that I had mistaken the GrabComponent function with the GrabbedComponent variable (UE documentation).
Will test it out again and get back to you soon.

Everything is working now, thanks a lot @QueueButton.

1 Like

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

Privacy & Terms