home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!math.fu-berlin.de!informatik.tu-muenchen.de!rz.uni-passau.de!hiwi170.rz.uni-passau.de!schmidt
- From: schmidt@rz.uni-passau.de (SCHMIDT GUIDO)
- Newsgroups: comp.lang.c++
- Subject: Re: Friend ..Overload Assignment opertr ..
- Date: Sat, 23 Jan 1993 14:18:19 GMT
- Organization: University of Passau - Germany
- Lines: 65
- Message-ID: <schmidt.32@rz.uni-passau.de>
- References: <1993Jan22.075317.21062@usl.edu>
- NNTP-Posting-Host: hiwi170.rz.uni-passau.de
-
- In article <1993Jan22.075317.21062@usl.edu> rks9954@usl.edu (Srinivasa Rao K) writes:
-
-
- >
-
-
- > Hi C++ masters,
-
- > I have small question ...
-
- > 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 ....
-
- >
- > Thanks for those who spend time reading this ....
-
-
-
-
- >Rao.
-
- Hello!
-
- operator=() is something like a constructor with built in destructor. You
- can specify as many different constructors for one class as you like.
- Likewise you can do for operator=().
- So why not have:
-
- class String {
- public:
- ...
- String& operator=( const String& aString ) { ... }
- String& operator=( char * aCharPtr ) { ... }
- String& operator=( const char aChar ) { ... }
- ...
- };
-
- I hope this will help you.
-
- Guido.
- --------------------------------------------------------------------
- - Guido Schmidt -
- - schmidt@rz.uni-passau.de -
- - Universitaet Passau, Germany -
- --------------------------------------------------------------------
-
-