[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #56953] Can not access private class propertie
From: |
Markus Ebner |
Subject: |
[Octave-bug-tracker] [bug #56953] Can not access private class properties from lambdas |
Date: |
Wed, 25 Sep 2019 18:55:40 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Firefox/68.0 |
URL:
<https://savannah.gnu.org/bugs/?56953>
Summary: Can not access private class properties from lambdas
Project: GNU Octave
Submitted by: seijikun
Submitted on: Wed 25 Sep 2019 10:55:38 PM UTC
Category: Interpreter
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Matlab Compatibility
Status: None
Assigned to: None
Originator Name:
Originator Email:
Open/Closed: Open
Discussion Lock: Any
Release: 5.1.0
Operating System: Any
_______________________________________________________
Details:
In Octave, it is not possible to access private class properties (via
self.<propertyname>) from within lambdas defined somewhere in the class.
Here is a small example that works in Matlab:
classdef TestClass
properties(Access = private)
privateProperty = 0;
end
methods
function self = TestClass()
self.privateProperty = 5;
fnPtr = @() disp(self.privateProperty);
fnPtr();
end
end
end
In Octave, this outputs the error:
error: subsref: property `privateProperty' has private access and cannot be
obtained in this context
error: called from
TestClass>@<anonymous> at line 9 column 16
TestClass at line 10 column 4
Workaround is one of:
- Remove the Access-clause on the properties
- Set Access to public (protected does not work either)
- Copy variable into "stack" before using it in the lambda, like:
tmpCopy = self.privateProperty;
fnPtr = @() disp(tmpCopy);
fnPtr();
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?56953>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Octave-bug-tracker] [bug #56953] Can not access private class properties from lambdas,
Markus Ebner <=