Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ equivalent of Matlab Abstract for class properties
    primarykey
    data
    text
    <p><strong>Short version:</strong><br> Consider the following pseudo-code:</p> <pre class="lang-cpp prettyprint-override"><code>class Foo { private: abstract type myVar; } // This class is abstract </code></pre> <p>How would you implement this behaviour in standard C++?</p> <hr> <p><strong>Long version:</strong><br> I have to port a lot of Obj-Oriented code from Matlab to C++. Note that I am the least experienced person in the world with Matlab and I do not use C++ since 2007.</p> <p>I googled a lot on this topic but i couldn't find a proper answer to my question. So here I am :)</p> <p>Let's say that you have this matlab class:</p> <pre class="lang-m prettyprint-override"><code>classdef Foo &lt; handle properties (Abstract, Dependent) A end properties B end methods (Abstract) computeA() end methods (Access = protected) function obj = Foo(bar) obj.B = Matlab.BlaBlaBla(bar) end end </code></pre> <p>This class (i suppose) cannot be allocated "directly" since it's constructor is protected. Also is property "A" is Abstract (ignore for a moment the fact that is also Dependent). MathWorks tells us that this means that:</p> <ul> <li>Concrete subclasses must redefine abstract properties without the Abstract attribute, and must use the same values for the SetAccess and GetAccess attributes as those used in the abstract superclass.</li> <li>Abstract properties cannot define set or get access methods (see Property Access Methods) and cannot specify initial values. The subclass that defines the concrete property can create set or get access methods and specify initial values.</li> </ul> <p>So how would you correctly translate such behaviour in C++? Would it be right if I do as follow? (By right I mean that it is not a bad design practice)</p> <pre class="lang-cpp prettyprint-override"><code>class Foo { private: type A; type B; protected: virtual void computeA() = 0; Foo(type bar) { this.B = SomeFoo(bar); } } </code></pre> <p>What I think (and I may be wrong) is that if I'm doing so one will have to do</p> <pre class="lang-cpp prettyprint-override"><code>class Subclass: Foo { protected: void computeA(){...} public: type A() { computeA(); return A; } //This is A getter that grants Dependent behavior } </code></pre> <p>Or otherwise get an error at compile time.</p> <p>Am i wrong? Is there a better way to do so? Also is the that right way to translate the Dependent keyword?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload