Mixining templates having functions with the same name
John Demme
me at teqdruid.com
Sun Apr 2 10:03:53 PDT 2006
Victor Nakoryakov wrote:
> Hello,
>
> Consider snipet:
>
> template T1()
> {
> void myproperty(real x) // line X
> {
> ...
> }
> }
>
> template T2()
> {
> real myproperty() // line Y
> {
> return ...;
> }
> }
>
> class C(alias M1, alias M2)
> {
> mixin M1!();
> mixin M2!();
>
> ...
> }
>
> ...
> auto c = new C!(T1, T2)
> ...
>
> Compilation of course gives an error: 'myproperty on line X conflicts
> with myproperty on line Y', this is expected dmd behaviour.
>
> But in this case I know what I do. So who know elegant solution do
> disambigue instanciation?
>
template T1()
{
void myproperty(real x) // line X
{
}
}
template T2()
{
real myproperty() // line Y
{
return 5;
}
}
class C(alias M1, alias M2)
{
mixin M1!();
mixin M2!();
}
void main()
{
auto c = new C!(T1,T2);
}
The above code compiles, links, and runs fine with DMD 0.150 on Linux.
~John Demme
More information about the Digitalmars-d
mailing list