Hi,
I’m trying to create a dynamic 2D array to pointers to objects (i.e. pointer to array of pointers to pointers)
The only way I thought I could approach this is through
type*** arrayName;
I’m getting the following error:
error : In BoardGrid: Missing '’ in Expected a pointer type*
Here’s a snippet of both the .h and .cpp code:
.h
UCLASS()
class MYBOARD_API ABoardGrid : public ABoardCell
{
GENERATED_UCLASS_BODY()
~ABoardGrid();
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Board)
TSubobjectPtr<USceneComponent> BoardDummyRoot;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Board)
ABoardCell*** MainBoardGrid;
UPROPERTY(EditAnywhere, Category = Board)
TSubclassOf<ABoardCell> SpawnedCell;
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Board)
int32 mNumBoardRows;
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Board)
int32 mNumBoardColumns;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Board)
float CellSpacing;
virtual void BeginPlay() override;
};
.cpp
void ABoardGrid::BeginPlay()
{
Super::BeginPlay();
MainBoardGrid = new ABoardCell**[mNumBoardRows];
for (int32 i = 0; i < mNumBoardRows; i++)
{
MainBoardGrid[i] = new ABoardCell*[mNumBoardColumns];
for (int32 j = 0; j < mNumBoardColumns; j++)
{
if (SpawnedCell != NULL)
{
UWorld* const World = ();
if (World)
{
FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
SpawnParams.Instigator = Instigator;
const float XOffset = j * CellSpacing;
const float YOffset = i * CellSpacing;
const FVector CellLocation = FVector(XOffset, YOffset, 0.f) + GetActorLocation();
FRotator CellRotation;
CellRotation.Yaw = 0.f;
CellRotation.Pitch = 0.f;
CellRotation.Roll = 0.f;
MainBoardGrid[i][j] = World->SpawnActor<ABoardCell>(SpawnedCell, CellLocation, CellRotation, SpawnParams);
}
}
else
MainBoardGrid[i][j] = NULL;
}
}
}
Then in the destructor function I’m completely deleting all allocated memory…but looks like c++ is complaining about the ABoardCell*** MainBoardGrid; declaration.
ABoardCell is a class publicly inheriting from AActor
Is the declaration valid?
Does ()->SpawnActor<>() return a pointer or a copy of an object?
I’ve seen straight c++ implementations that uses the *** declaration. It’s a dynamic 2D table that holds pointers to objects.
Any help is appreciated