All actors automatically have a root component, you just need to create it in the constructor if you want to use their default one. Here is some code which should do attachments correctly:
Apickup::Apickup()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
RootComponent = CreateAbstractDefaultSubobject<USceneComponent>(TEXT("pickuproot"));
staticmesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("pickupmesh"));
staticmesh->SetupAttachment(RootComponent);
touchsphere = CreateDefaultSubobject<USphereComponent>(TEXT("touchsphere"));
touchsphere->SetupAttachment(RootComponent);
}