Polymorphic question for noob!

So I have created a few hundred randomly different child objects of a Base class A and put them in a TMap<FName, A*> MyObjects;

I have a method in A that is overridden in the children B, C, D etc that I need to call that provides some Initialization/spawn parameters during the creation of B, C, D etc

I know I can Cast to call the overridden method in B,C,D etc, but as the Map has many different types of A, I would have to set up a loop with a lengthy if…elseif…elseif block to cast each object after I have determined what type it is.

I just want to loop over the TMap to get the A’s and call the overridden method of B,C,D…etc

Is there a way to do this I don’t yet know of?

Thanks

You don’t need to test their class - as long as you’ve correctly defined the base class A as virtual, and are correctly deriving that in your other classes with an override - and your creating the object as the newly derived class you can just call A and it will use the correct derived method.

It isnt though, its calling the base class method.
My Base Class Method

public:
	UFUNCTION()
		virtual bool ProcessDataTables(FName TheFlag = "", FName TheRowMode = "");

An example overridden method

public:
	virtual bool ProcessDataTables(FName TheFlag = "MAN_SEQ", FName TheExtractionModel = "LEVEL") override;

So when I call ProcessDataTables() from looping over the base class, i am not getting the default variables , because I can clearly see from the results that the output is wrong. If I cast and call ProcessDataTables(), all is working good.

This may not be the best programming method, so if necessary I will change it if this cannot be made to work this way.

How are you creating the overridden class? It sounds like you’re creating a Base Class object…