home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!news.univie.ac.at!scsing.switch.ch!univ-lyon1.fr!ghost.dsi.unimi.it!rpi!usenet.coe.montana.edu!saimiri.primate.wisc.edu!sdd.hp.com!spool.mu.edu!sgiblab!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Subject: Re: Friend ..Overload Assignment opertr ..
- Message-ID: <1993Jan27.142604.16923@ucc.su.OZ.AU>
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: MAXTAL P/L C/- University Computing Centre, Sydney
- References: <1993Jan22.075317.21062@usl.edu> <C19838.JM3@cs.uiuc.edu>
- Date: Wed, 27 Jan 1993 14:26:04 GMT
- Lines: 42
-
- In article <C19838.JM3@cs.uiuc.edu> pjl@cs.uiuc.edu (Paul Lucas) writes:
- >In <1993Jan22.075317.21062@usl.edu> rks9954@usl.edu (Srinivasa Rao K) writes:
- >
- >> I am writing a "string" class which i should be able
- >> to use like
- >
- >> string str1;
- >> str1 = "Hello world" ;
- >
- >> But We canot use a friend to overload the assignment oprator.
- >> So finally I had to convince myself to use something like
- >
- >> str1 <= "Hello world"
- >
- >> which works.
- >
- >> Is there any way to do the first method ....
- >
- > No. operator=() must be a member. Period. Everybody defines it
- > this way and has no problem. Whats wrong with it being a member?
-
- Actually, I suggest instead a constructor:
-
- string::string(char *);
-
- Then you dont need to bother with assignment from a char*:
-
- string s;
- s="Hello";
-
- will work because the assignment operator:
-
- operator=(const string&)
-
- will cause conversion from char* to string before doing the assignment.
- This is less efficient but simpler.
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;------ SCIENTIFIC AND ENGINEERING SOFTWARE ---ph: 2 799 8223 --------
-