Announcement

Collapse
No announcement yet.

array of parent structs does no accept child structs

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • replied
    Structs, unlike classes, are not polymorphic. In the .NET world you'd call them "value types", because the struct value itself would be stored in the array, not a reference to the struct value. Consequently, if you derive a struct from another struct, it will be larger and by design not fit into an array of the smaller struct type.

    Leave a comment:


  • started a topic array of parent structs does no accept child structs

    array of parent structs does no accept child structs

    Code:
    struct Robot
    {
    	var() String robotName;
    };
    
    struct RobotWithAntenna extends Robot
    {
    	var() String antennaName;
    };
    
    function Test()
    {
    	local RobotWithAntenna myAntennaRobot;
    	local array<Robot> robots;
    	
    	myAntennaRobot.robotName = "Hans";
    	myAntennaRobot.antennaName = "Model X v.2";
    	
    	robots.AddItem(myAntennaRobot);
    }
    Causes Error:

    Type mismatch in additem(...)
    How do I do that?
Working...
X