Initialize field in base class

2 posts / 0 new
Last post
Offline
Last seen: 3 years 10 months ago
Joined: 05/27/2020
Posts: 1
Initialize field in base class
Is this valid?  If not, is there a way to do something like this where I can initialize a field in a parent class with a const in a child class?

valuetype MyBaseValueType  {
    public string  member;
};

valuetype MyValueType:
MyBaseValueType  {
    public const string member2 = "Member Name";
    member = member2; 
};

valuetype Message: MyValueType{
    public long data;
};    
Offline
Last seen: 6 days 21 hours ago
Joined: 04/02/2013
Posts: 195

You can try the @default annotation to set a default value for a field:

 

struct Test {

@default("Hello") string str;

@default(43) int32 value;

};