Re: shared interfaces

2015-02-15 Thread anonymous via Digitalmars-d-learn
On Sunday, 15 February 2015 at 10:43:46 UTC, Andrey Derzhavin 
wrote:
what is wrong in declarations, if I need to declare shared 
classes D and C?


`shared` on a class/interface makes all members shared. And 
that's all it does.


So this:


interface IA
{
void fnA();
}
shared class C : IA
{
override void fnA() {}
}


is the same as this:



interface IA
{
void fnA();
}
class C : IA
{
override void fnA() shared {}
}


But you can't override a non-shared method with a shared one, 
hence the error.


So, if you need to override non-shared methods, you can't mark 
the whole class shared. Instead, you have to mark the shared 
members individually. Like so:



interface IA
{
void fnA();
}
shared interface IC : IA
{
void fnC();
}
class D : IC
{
override void fnC() shared {}
override void fnA() {}
}



Re: shared interfaces

2015-02-15 Thread Andrey Derzhavin via Digitalmars-d-learn

On Sunday, 15 February 2015 at 14:59:20 UTC, anonymous wrote:

Hm? Works for me. What error do you get, or what doesn't work? 
Which compiler are you using, which version?



The error Error: function main.C.fnA does not
override any function, did you mean to override 'main.IA.fnA'? 
has occured ((

I'm using DMD 2.066.1 compiler.


Re: shared interfaces

2015-02-15 Thread Andrey Derzhavin via Digitalmars-d-learn

On Sunday, 15 February 2015 at 14:59:20 UTC, anonymous wrote:

Sorry everything is OK. It's my fault. Thanks))



Re: shared interfaces

2015-02-15 Thread Andrey Derzhavin via Digitalmars-d-learn

On Sunday, 15 February 2015 at 11:30:46 UTC, anonymous wrote:
On Sunday, 15 February 2015 at 10:43:46 UTC, Andrey Derzhavin 
wrote:
what is wrong in declarations, if I need to declare shared 
classes D and C?


`shared` on a class/interface makes all members shared. And 
that's all it does.


So this:


interface IA
{
void fnA();
}
shared class C : IA
{
override void fnA() {}
}


is the same as this:



interface IA
{
void fnA();
}
class C : IA
{
override void fnA() shared {}
}


But you can't override a non-shared method with a shared one, 
hence the error.


So, if you need to override non-shared methods, you can't mark 
the whole class shared. Instead, you have to mark the shared 
members individually. Like so:



interface IA
{
void fnA();
}
shared interface IC : IA
{
void fnC();
}
class D : IC
{
override void fnC() shared {}
override void fnA() {}
}


Try to compile your example, it is wrong.


Re: shared interfaces

2015-02-15 Thread anonymous via Digitalmars-d-learn
On Sunday, 15 February 2015 at 12:34:50 UTC, Andrey Derzhavin 
wrote:

On Sunday, 15 February 2015 at 11:30:46 UTC, anonymous wrote:

[...]


interface IA
{
   void fnA();
}
shared interface IC : IA
{
   void fnC();
}
class D : IC
{
   override void fnC() shared {}
   override void fnA() {}
}


Try to compile your example, it is wrong.


Hm? Works for me. What error do you get, or what doesn't work? 
Which compiler are you using, which version?