Get rid of the pointers for great good™. And while we’re at it, move as much as you can to the constructor.
AnotherClass classB::setupData()
{
AnotherClass a(/* setup data */);
return a;
}
Should get yourself rid of more than one problem at once.