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.

Reply via email to