View previous topic :: View next topic |
Author |
Message |
mutable
Joined: 22 Jun 2010 Posts: 87
|
Posted: Mon Mar 14, 2011 11:36 am Post subject: one method as template, one normal -> don't work? |
|
|
Hi, today i tried something like this
Code: |
import std.stdio;
class Rect {
private short _x, _y;
this(in short x, in short y) {
this._x = x;
this._y = y;
}
void x(E)(in E x) {
this._x = cast(short) x;
}
short x() const {
return this._x;
}
short y() const {
return this._y;
}
void y(E)(in E y) {
this._y = cast(short) y;
}
}
void main() {
Rect r1 = new Rect(42, 23);
writefln("r1 %d:%d", r1.x(), r1.y());
r1.y(3.1456);
//writefln("r1 change %d:%d", r1.x, r1.y);
}
|
And i get this errors
Quote: |
dmd -O "rect_tpl_teils.d" (im Verzeichnis: C:\Users\White\Desktop)
rect_tpl_teils.d(15): Error: function rect_tpl_teils.Rect.x conflicts with template rect_tpl_teils.Rect.x(E) at rect_tpl_teils.d(11)
rect_tpl_teils.d(23): Error: template rect_tpl_teils.Rect.y(E) conflicts with function rect_tpl_teils.Rect.y at rect_tpl_teils.d(19)
Kompilierung fehlgeschlagen.
|
After a lot of reading i fixed this "bug" (?)
Code: |
import std.stdio;
class Rect {
private short _x, _y;
this(in short x, in short y) {
this._x = x;
this._y = y;
}
void x(E)(in E x) {
this._x = cast(short) x;
}
short x(E = short)() const {
return this._x;
}
short y(E = short)() const {
return this._y;
}
void y(E)(in E y) {
this._y = cast(short) y;
}
}
void main() {
Rect r1 = new Rect(42, 23);
writefln("r1 %d:%d", r1.x(), r1.y());
r1.y(3.1456);
//writefln("r1 change %d:%d", r1.x, r1.y);
}
|
I'm confused, should the compiler don't notice this itself?
Sorry for my bad english. |
|
Back to top |
|
|
mutable
Joined: 22 Jun 2010 Posts: 87
|
Posted: Tue Mar 15, 2011 4:13 pm Post subject: |
|
|
Most of the users here are not really active, isn't it?
After a little researching, i found this
The Topic can be closed (; |
|
Back to top |
|
|
mutable
Joined: 22 Jun 2010 Posts: 87
|
Posted: Wed Mar 16, 2011 4:46 am Post subject: |
|
|
(spammer) wrote: | mutable wrote: | Most of the users here are not really active, isn't it?
After a little researching, i found this
The Topic can be closed (; |
They really helped me about my similar problem. Thanks for sharing this dude. |
No problem.
Short time before i had found it, i have written an Article in german.
Maybe this article will help (or enjoy) you also. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|