Attach Object to Skeletal Mesh Socket C++

this should work

FName fnWeaponSocket = TEXT("WeaponSocket");
m_cUClassWeapon = StaticLoadClass(UObject::StaticClass(), nullptr, TEXT("/Game/Blueprints/CharacterController/BP_Pistol.BP_Pistol_C"));
m_cWeapon = GetWorld()->SpawnActor<AWeapon>(m_cUClassWeapon, spawnParams);
m_cWeapon->AttachRootComponentTo(GetMesh(), fnWeaponSocket, EAttachLocation::SnapToTarget, true);