View previous topic :: View next topic |
Author |
Message |
Nova
Joined: 18 Sep 2004 Posts: 23
|
Posted: Mon Dec 13, 2004 12:29 pm Post subject: equal operator? |
|
|
Is there an opFunction that handles a single equal sign?
For example if I have the following: myclass = "new value";
Is there any function in myclass that would get called with "new value" as its argument? |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Mon Dec 13, 2004 6:34 pm Post subject: |
|
|
No, try a constructor.
myclass = new MyClass("new value"); |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Nova
Joined: 18 Sep 2004 Posts: 23
|
Posted: Mon Dec 13, 2004 9:48 pm Post subject: |
|
|
Vathix wrote: | No, try a constructor.
myclass = new MyClass("new value"); |
But that doesn't work if the class has already been instanciated. So do you mean theres no way to have an equal operator? |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Ant
Joined: 06 Mar 2004 Posts: 306 Location: Canada
|
Posted: Mon Dec 13, 2004 10:14 pm Post subject: opAssign |
|
|
Vathix wrote: | No, try a constructor.
myclass = new MyClass("new value"); |
I don't dare to suggest this on the D group but if there was I could do:
String str;
str = "Hello There";
instead of
str = new String("Hello There");
of course then I would also do:
str = 1;
which could start to get confusing...
I would vote for it...
Ant |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Nova
Joined: 18 Sep 2004 Posts: 23
|
Posted: Mon Dec 13, 2004 10:34 pm Post subject: |
|
|
Yea, I would too. Right now I have the following and would kinda like the alternative I mentioned but oh well.
MyClass myclass;
[ ... ]
myclass = new MyClass();
[ ... ]
myclass.setValue("new value"); |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Wed Dec 15, 2004 8:26 am Post subject: |
|
|
This has actually come up a few times before, try searching the newsgroup for some of Walter's reasoning... I don't remember enough to try to repeat it. As for your current method, you might also consider a change in style, a la:
MyClass myclass;
[ ... ]
myclass = new MyClass();
[ ... ]
myclass.value("new value");
This is consistant with D 'properties', so you could then do:
myclass.value = "new value";
Which isn't quite what you want, but its getting there. ![Smile](images/smiles/icon_smile.gif) _________________ Chris Nicholson-Sauls |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Nova
Joined: 18 Sep 2004 Posts: 23
|
Posted: Wed Dec 15, 2004 3:05 pm Post subject: |
|
|
csauls wrote: | myclass.value = "new value"; |
Is this method only for a value() method or can it be used on any class method with one single argument to pass? |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
|