Re: Weird UFC and opCall issues

2015-01-03 Thread Darrell via Digitalmars-d-learn
Thanks for the feedback. With classes, you need to create an instance Need to read up classes vs struct. This bit of syntax was very intresting. /* Alternatively, you can move test() inside Test as a static opCall: static Test opCall() { return new Test(); } Then, the

Re: Weird UFC and opCall issues

2015-01-03 Thread Ali Çehreli via Digitalmars-d-learn
On 01/03/2015 12:26 PM, Darrell wrote: > Fails with: > t.d(34): Error: need 'this' for 'opCall' of type 'int()' > > Also opCall seems to be required to create a range. D has a feature that does not exists e.g. in C++: You can call the type itself as a function. The 'Test()' syntax is a cal

Re: Weird UFC and opCall issues

2015-01-03 Thread ted via Digitalmars-d-learn
Darrell wrote: > Seems when creating your own ranges they can't be a class. > Must be a struct or Segmentation fault (core dumped) will follow. > > This works as long as Test is a struct. > > struct Test > { >@property int front() >{ > return 2; >} > >void popFront() >{

Re: Weird UFC and opCall issues

2015-01-03 Thread Darrell via Digitalmars-d-learn
Seems when creating your own ranges they can't be a class. Must be a struct or Segmentation fault (core dumped) will follow. This works as long as Test is a struct. struct Test { @property int front() { return 2; } void popFront() { } enum bool empty = false; }; static asser

Re: Weird UFC and opCall issues

2015-01-03 Thread Darrell via Digitalmars-d-learn
Ooops. Test() wasn't valid. Still working to create a range object that iterates over an internal data struct. But this was may error. On Saturday, 3 January 2015 at 20:26:41 UTC, Darrell wrote: Fails with: t.d(34): Error: need 'this' for 'opCall' of type 'int()' Also opCall seems to be

Re: Weird UFC and opCall issues

2015-01-03 Thread Darrell via Digitalmars-d-learn
Fails with: t.d(34): Error: need 'this' for 'opCall' of type 'int()' Also opCall seems to be required to create a range. class Test { int opCall() { return 1; } @property int front() { return 2; } void popFront() { } @property bool empty() { return false;

Re: Weird UFC and opCall issues

2014-12-17 Thread Jay Pinkman via Digitalmars-d-learn
On Thursday, 18 December 2014 at 02:45:01 UTC, Adam D. Ruppe wrote: D doesn't have a really clean separation between static and non-static methods. hmm.. i thought that's what 'static' is for. It sees an opCall and thinks you're trying to call it, but since it isn't static, it complains you d

Re: Weird UFC and opCall issues

2014-12-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 18 December 2014 at 02:42:32 UTC, Jay Pinkman wrote: source/main.d(12): Error: need 'this' for 'opCall' of type 'void(string y)' D doesn't have a really clean separation between static and non-static methods. It sees an opCall and thinks you're trying to call it, but since it isn

Weird UFC and opCall issues

2014-12-17 Thread Jay Pinkman via Digitalmars-d-learn
void main () { struct X { string x; void opCall (string y) { import std.stdio; writeln("%s %s!", x, y); } } auto x = X("hello"); "world".x; } source/main.d(12): Error: need 'this' for 'opCall' of type 'void(string y)' source/main