d插件构造器2
template C ()
{
this (int i)
{
}
}
class A
{
mixin C;
this ()
{
}
}
void main ()
{
auto a = new A(3);
}
可这样:
template C ()
{
void fun(int i)
{
}
}
class A
{
mixin C f;
alias fun = f.fun;
void fun ()
{
}
}
void main ()
{
auto a = new A();
a.fun();
}
对普通函数,可用重载集显式插入.但因为构造器没有名字,所以不行.试用__ctor,也不行.解决方法,是应该允许:
template C ()
{
this (int i)
{
.......
}
}
class A
{
mixin C f;
alias __ctor = f.__ctor;
// 应该允许.
....
this ()
{
}
}
void main ()
{
auto a = new A(3);
}
临时方法:
template C ()
{
this (int i)
{
}
}
class A
{
mixin C f;
this ()
{
}
alias __ctor = f.__ctor;
}
void main ()
{
auto a = new A(3);
}
似乎只有在已定义符号时,__ctor别名才有用.
这里
以前,禁止在重载集中加构造器,因为禁止用__ctor来定义符号.然而,这使得不能在mixin模板中定义构造器,来添加到构造器重载集中.应允许它.
浙公网安备 33010602011771号