- Index
- » Programming
- » Modelica Language
- » Inheritance with data value...
Page Start Prev 1 Next End
Inheritance with data value redefinition [fritz,p.65]
Inheritance with data value redefinition [fritz,p.65]
Jan-29-16 08:09:40
I found some strange case in Fritz tutorial, page 65:
slide: Inheriting definitions
Code:
record ColorData
parameter Real red = 0.2;
parameter Real blue = 0.6;
Real green;
end ColorData;
class ErrorColor
extends ColorData;
parameter Real blue = 0.6;
parameter Real red = 0.3; // this line strangly marked as error due to _value_ redefenition
equation
red + blue + green = 1;
end ErrorColor;
Isn't inheritance must garantee this case as inherited class behavior extension ?
Re: Inheritance with data value redefinition [fritz,p.65]
Jan-29-16 10:56:12
If you have multiple elements with the same name that come from the local scope and the extends scope the have to be *identical* which is not the case in this particular example. The correct way to deal with changes is via modifications on the extends clause:
Code:
record ColorData
parameter Real red = 0.2;
parameter Real blue = 0.6;
Real green;
end ColorData;
class ErrorColor
extends ColorData(red=0.3, blue = 0.12);
equation
red + blue + green = 1;
end ErrorColor;
- adrpo
- 885 Posts
Page Start Prev 1 Next End
- Index
- » Programming
- » Modelica Language
- » Inheritance with data value...
There are 0 guests and 0 other users also viewing this topic