Accessing members of super class [message #1851555] |
Fri, 08 April 2022 12:07 |
Fabian Sow Messages: 9 Registered: January 2022 |
Junior Member |
|
|
Hello,
I am having problems accessing members of a superclass. I tried a simple example, to see if members can be accessed from subclasses.
In this simple example it works, while in my actual code it does not
# Example 1
type class @abstract DeviceController runs on MTC{
var charstring v_dummy := "";
public function @abstract f_do_sth();
}
type class Device extends DeviceController runs on MTC{
public function f_do_sth() {
log(v_dummy);
}
}
# Example 2
In my actual project, I get an error in a subclass, where the compiler complains that the member was not defined. But it is exactly defined as in the above example.
module CellularCommonDeviceController {
...
public type class @abstract CellularDeviceController runs on Cellular_Node_CT {
var charstring cmd := "";
...
}
}
module Cs {
...
type class @final CsGr851 extends CellularDeviceController runs on Cellular_Node_CT {
var ModemCapability v_cap;
create():CellularDeviceController("") {
v_cap := {3, 0, false}
}
}
...
}
In the generated c++ code I see that cmd is a protected member in the superclass. I can access the member from the class itself, but accessing it from a subclass seems to be a problem somehow. Accessing methods is not a problem.
Cs .cc:334:33: error: 'cmd' is not a member of 'CellularCommonDeviceController'
334 | CellularCommonDeviceController::cmd = cs_20;
##
I have various imports, but nowhere another variable with that name is declared. Declaring a local variable cmd in the subclass works without any issues.
Does someone know by what that behavior might be caused?
|
|
|
|
|
Re: Accessing members of super class [message #1851569 is a reply to message #1851559] |
Fri, 08 April 2022 16:46 |
Miklos Magyari Messages: 6 Registered: March 2022 |
Junior Member |
|
|
hi,
you are right, the generated code has an issue if the parent class and the subclass are defined in different modules.
For inherited fields, a <module-name>:: prefix is added (mistakenly). It should be simply the field name with no prefix.
The example probably works as the parent and child classes are in the same module and in this case, the generated code is this->cmd
We will look at this issue.
br,
Miki
[Updated on: Fri, 08 April 2022 16:46] Report message to a moderator
|
|
|
|
|
Re: Accessing members of super class [message #1852043 is a reply to message #1851886] |
Wed, 27 April 2022 08:26 |
Fabian Sow Messages: 9 Registered: January 2022 |
Junior Member |
|
|
Thank you for the timely update. However, I am now facing different issues which might not be caused by this fix tough, since I
upgrade from the 8.0.0 release to the latest commit.
I have the following setup of classes:
CellularInterface -> abstract class with only abstract methods
NbInterface -> abstract class extending cellular interface but only having abstract methods as well
CellularDeviceController runs on Node_CT -> abstract class implementing NbInterface, but leaving some methods abstract to be implemented by the concrete class
Cs runs on Node_CT -> final class implementing CellularDeviceController
I use this component:
Node_CT -> has different port types and the above mentioned interface types, e.g. NbInterface
In a separate module I am using a component variable of type NbInterface (vc_nb) and instantiate the concrete class `Cs`
vc_nb := csGr851.create();
With the titan release with Tag 8.0.0 all builds and executes.
When I pull to the latest commit and build titan again, I get errors in the generated code, telling me that I can't call new on my concrete class, because there appears to be pure virtual functions in my class. These methods that are complained about, are however implemented in the class.
CommonFunctionality.cc:167:79: error: invalid new-expression of abstract class type 'cs::csGr851'
167 | CommonInterface::Node__CT_component_vc__nbiot = new cs::csGr851();
| ^
cs.hh:68:7: note: because the following virtual functions are pure within 'cs::csGr851':
68 | class csGr851 : public CellularCommonDeviceController::CellularDeviceController {
| ^~~~~~~
CommonInterface.hh:133:14: note: 'virtual void CommonInterface::CellularInterface::f__select__operator(const BOOLEAN&, CommonInterface::CellularInterface_defpar_type_0)'
133 | virtual void f__select__operator(const BOOLEAN& auto_, CellularInterface_defpar_type_0 plmn_defpar) = 0;
| ^~~~~~~~~~~~~~~~~~~
Do you have an idea, what change might cause this behavior or what might go wrong?
Best regards
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05795 seconds