digitalmars.D.learn - Should this work?
- bobef (20/20) Jan 30 2010 I get these errors DMD 1.055:
- Jacob Carlborg (5/25) Jan 30 2010 Since "a" is a method and when you do "typeof(X)" it tries to call the
- bobef (2/37) Jan 30 2010 This is not true. You can't call neither A.a nor A.b because A is a clas...
- Jacob Carlborg (13/50) Jan 30 2010 That's true, but you can still try to call it.
- bobef (2/60) Jan 30 2010 I am not sure it should try to call anything. If it did A.b would fail b...
I get these errors DMD 1.055: (void(char[] _param_0))() bug.d(2): Error: expected 1 function arguments, not 0 (void(char[] _param_0))() bug.d(15): Error: template instance bug.Foo!(a) error instantiating //code---------------------------------------------------------------------------------------------- void Foo(alias X)() { pragma(msg,typeof(X).stringof); } class A { void a(char[]) { } void b() { } } void main() { Foo!(A.a)(); //doesnt work Foo!(A.b)(); //works } //end of code ----------------------------------------------------------------------
Jan 30 2010
On 1/30/10 14:06, bobef wrote:I get these errors DMD 1.055: (void(char[] _param_0))() bug.d(2): Error: expected 1 function arguments, not 0 (void(char[] _param_0))() bug.d(15): Error: template instance bug.Foo!(a) error instantiating //code---------------------------------------------------------------------------------------------- void Foo(alias X)() { pragma(msg,typeof(X).stringof); } class A { void a(char[]) { } void b() { } } void main() { Foo!(A.a)(); //doesnt work Foo!(A.b)(); //works } //end of code ----------------------------------------------------------------------Since "a" is a method and when you do "typeof(X)" it tries to call the method but since it takes one parameter it fails. "b" doesn't fail because it doesn't take any parameters. This is all because of the optional parentheses in function calls. Change to: "typeof(&X)".
Jan 30 2010
Jacob Carlborg Wrote:On 1/30/10 14:06, bobef wrote:This is not true. You can't call neither A.a nor A.b because A is a class, not an instance of a class - there is no this. Maybe I should file a bug.I get these errors DMD 1.055: (void(char[] _param_0))() bug.d(2): Error: expected 1 function arguments, not 0 (void(char[] _param_0))() bug.d(15): Error: template instance bug.Foo!(a) error instantiating //code---------------------------------------------------------------------------------------------- void Foo(alias X)() { pragma(msg,typeof(X).stringof); } class A { void a(char[]) { } void b() { } } void main() { Foo!(A.a)(); //doesnt work Foo!(A.b)(); //works } //end of code ----------------------------------------------------------------------Since "a" is a method and when you do "typeof(X)" it tries to call the method but since it takes one parameter it fails. "b" doesn't fail because it doesn't take any parameters. This is all because of the optional parentheses in function calls. Change to: "typeof(&X)".
Jan 30 2010
On 1/30/10 14:47, bobef wrote:Jacob Carlborg Wrote:That's true, but you can still try to call it. void main () { A.a; } The above results in: Error: function A.a (char[]) does not match parameter types () Error: expected 1 function arguments, not 0 When I add the correct argument I get this result: Error: need 'this' to access member a Apparently it tries to match the arguments before it checks if "this" is available.On 1/30/10 14:06, bobef wrote:This is not true. You can't call neither A.a nor A.b because A is a class, not an instance of a class - there is no this. Maybe I should file a bug.I get these errors DMD 1.055: (void(char[] _param_0))() bug.d(2): Error: expected 1 function arguments, not 0 (void(char[] _param_0))() bug.d(15): Error: template instance bug.Foo!(a) error instantiating //code---------------------------------------------------------------------------------------------- void Foo(alias X)() { pragma(msg,typeof(X).stringof); } class A { void a(char[]) { } void b() { } } void main() { Foo!(A.a)(); //doesnt work Foo!(A.b)(); //works } //end of code ----------------------------------------------------------------------Since "a" is a method and when you do "typeof(X)" it tries to call the method but since it takes one parameter it fails. "b" doesn't fail because it doesn't take any parameters. This is all because of the optional parentheses in function calls. Change to: "typeof(&X)".
Jan 30 2010
Jacob Carlborg Wrote:On 1/30/10 14:47, bobef wrote:I am not sure it should try to call anything. If it did A.b would fail because of no this. So I guess nothing is actually called. Anyway it is a bug, I filed it :)Jacob Carlborg Wrote:That's true, but you can still try to call it. void main () { A.a; } The above results in: Error: function A.a (char[]) does not match parameter types () Error: expected 1 function arguments, not 0 When I add the correct argument I get this result: Error: need 'this' to access member a Apparently it tries to match the arguments before it checks if "this" is available.On 1/30/10 14:06, bobef wrote:This is not true. You can't call neither A.a nor A.b because A is a class, not an instance of a class - there is no this. Maybe I should file a bug.I get these errors DMD 1.055: (void(char[] _param_0))() bug.d(2): Error: expected 1 function arguments, not 0 (void(char[] _param_0))() bug.d(15): Error: template instance bug.Foo!(a) error instantiating //code---------------------------------------------------------------------------------------------- void Foo(alias X)() { pragma(msg,typeof(X).stringof); } class A { void a(char[]) { } void b() { } } void main() { Foo!(A.a)(); //doesnt work Foo!(A.b)(); //works } //end of code ----------------------------------------------------------------------Since "a" is a method and when you do "typeof(X)" it tries to call the method but since it takes one parameter it fails. "b" doesn't fail because it doesn't take any parameters. This is all because of the optional parentheses in function calls. Change to: "typeof(&X)".
Jan 30 2010