Simple C++ script in Unreal Engine 4 to attach a mesh component to an actor:
UStaticMeshComponent* helicopter;
helicopter = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("HELICOPTER"));
helicopter->SetupAttachment(RootComponent);
helicopter->bCastDynamicShadow = true;
helicopter->CastShadow = true;
static ConstructorHelpers::FObjectFinder<UStaticMesh> BaseMeshAsset(TEXT(path_mesh));
if (BaseMeshAsset.Object) {
helicopter->SetStaticMesh(BaseMeshAsset.Object);
}