On Friday, 4 October 2013 at 05:07:53 UTC, Zhouxuan wrote:
////////////////////////////////////////////////////////////
//case 1
class A
{
abstract void foo();
}
class B : A
{
static if( __traits(isAbstractClass, typeof(this) ))
this is invalid here. Not sure what you try to achieve via this
static if.
{
}
override void foo()
{
}
}
void main()
{
B b = new B();
}
//Error: cannot create instance of abstract class B
That is a bug.
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//case 2
abstract class A
{
void foo();
}
class B : A
{
static if( __traits(isAbstractClass, typeof(this) ))
{
}
override void foo()
{
}
}
void main()
{
B b = new B();
}
//Okay
It shouldn't, A.foo is not defined. You should get a link error.
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//case 3
class A
{
abstract void foo();
}
class B : A
{
override void foo()
{
}
}
void main()
{
B b = new B();
}
//Okay
This one work as expected :D
////////////////////////////////////////////////////////////
How awkward it is given that "D is as old as C#"!
Do you guys never used abstract class?
Not that much. Note that error comes up when abstract is mixed
with static if and compile time reflection, both are not present
in C#.