An interface function that returns values ​​from classes that implement the interface

I have interface with one function:

IInterface: {
TArray<IInterface*> GetItems();
}

And I have two classes that implements that interface and dependent on each other:

Class A: IInterface {
TArray<ClassB*> Items;

TArray<IInterface> GetItems() {
return Items;
    }

}

Class B: IInterface {
TArray<ClassA*> Items;

TArray<IInterface*> GetItems() {
return Items;
    }

}

But in editor I have an error:

Cannot convert value of type TArray<ClassA*> to return type TArray<IInterface*>

So I have a question: What the correct way to implement that behavior?

You can’t have an interface as an element of an array unless you use TScriptInterface

as mentioned in this thread

But you can in this place simplify it by having the TArray hold a UObject (a base class) in the interface

I made an example project that demonstrates this with a implementation:

Intface.zip (35.5 KB)

Just regenerate the UPROJECT file (right click and generate solution)