www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - is there a way to define a pure base class that forces pureness of

reply dennis luehring <dl.soluz gmx.net> writes:
i've got something like an streaming/converter system
and parts of the specialised converters are stateless other statefull

is there any way to force pureness/stateless-ness through the base
class or an interface in D?
Feb 02 2013
parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 02/02/2013 02:23 AM, dennis luehring wrote:
 i've got something like an streaming/converter system
 and parts of the specialised converters are stateless other statefull

 is there any way to force pureness/stateless-ness through the base
 class or an interface in D?
That seems to be the case: interface I { int foo() const pure; } int g; class C : I { int foo() const { return g; // ERROR: pure function 'deneme.C.foo' cannot access // mutable static data 'g' } } void main() { auto o = new C; o.foo(); } Note that there is no 'pure' on C.foo; it is inherited from I.foo. Ali
Feb 02 2013