FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

equal operator?

 
Post new topic   Reply to topic     Forum Index -> Tutorials
View previous topic :: View next topic  
Author Message
Nova



Joined: 18 Sep 2004
Posts: 23

PostPosted: Mon Dec 13, 2004 12:29 pm    Post subject: equal operator? Reply with quote

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
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Mon Dec 13, 2004 6:34 pm    Post subject: Reply with quote

No, try a constructor.
myclass = new MyClass("new value");
Back to top
View user's profile Send private message
Nova



Joined: 18 Sep 2004
Posts: 23

PostPosted: Mon Dec 13, 2004 9:48 pm    Post subject: Reply with quote

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
View user's profile Send private message
Ant



Joined: 06 Mar 2004
Posts: 306
Location: Canada

PostPosted: Mon Dec 13, 2004 10:14 pm    Post subject: opAssign Reply with quote

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
View user's profile Send private message
Nova



Joined: 18 Sep 2004
Posts: 23

PostPosted: Mon Dec 13, 2004 10:34 pm    Post subject: Reply with quote

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
View user's profile Send private message
csauls



Joined: 27 Mar 2004
Posts: 278

PostPosted: Wed Dec 15, 2004 8:26 am    Post subject: Reply with quote

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
_________________
Chris Nicholson-Sauls
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
Nova



Joined: 18 Sep 2004
Posts: 23

PostPosted: Wed Dec 15, 2004 3:05 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Tutorials All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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