digitalmars.D - DMD does not allow stringof on function alias of a function that
- d coder (21/21) Jun 02 2012 Greetings All
- Jacob Carlborg (9/30) Jun 02 2012 I'm guessing that the problem is that you can call a function without
Greetings All Using DMD 2.059, the following code does not compile. DMD does not allow me to apply stringof on a function alias of a function that takes one or more arguments. It compiles and runs fine for functions that do not take any arguments. Is it a bug, or am I doing something wrong here? Regards - Puneet class Foo { void foo() { } void frop(int n) { } } void callfoo(alias F, T) (T t) { import std.stdio; writeln(F.stringof); } void main() { Foo f = new Foo(); callfoo!(Foo.foo)(f); // This works callfoo!(Foo.frop)(f); // This does not work }
Jun 02 2012
On 2012-06-02 13:40, d coder wrote:Greetings All Using DMD 2.059, the following code does not compile. DMD does not allow me to apply stringof on a function alias of a function that takes one or more arguments. It compiles and runs fine for functions that do not take any arguments. Is it a bug, or am I doing something wrong here? Regards - Puneet class Foo { void foo() { } void frop(int n) { } } void callfoo(alias F, T) (T t) { import std.stdio; writeln(F.stringof); } void main() { Foo f = new Foo(); callfoo!(Foo.foo)(f); // This works callfoo!(Foo.frop)(f); // This does not work }I'm guessing that the problem is that you can call a function without parentheses in D (this is how properties are implemented). So the problem is that it will actually try and call the function with no arguments, which will fail since it expects, in this case, an int. Try taking the address of the function first: writeln(&F.stringof); -- /Jacob Carlborg
Jun 02 2012