Re: [Dev-C++] How would you write a method returning a string ?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Adam J. <aj...@i-...> - 2007-07-23 01:52:59
|
>>Of course, as long as you know what youre doing, youre fine. But I >>wouldnt advice people, specially novices, doing that sort of function. I would definitely agree with that statement. You really need a good reason to do that. What you are trying to do is potentially dangerous. I would also document this in comments what you are doing, just in case other programmers use your class. There are safer ways to accomplish what you are trying to do..... :) -Adam Jones -----Original Message----- From: dev...@li... [mailto:dev...@li...] On Behalf Of matheus ribeiro Sent: Sunday, July 22, 2007 8:41 PM Cc: dev...@li... Subject: Re: [Dev-C++] How would you write a method returning a string ? > I have many classes that manipulate the string and then returns it either as > a 'const char*', 'std::string', 'int', and so on and so forth, the method is > just part of the class, so instead of writing a stand alone function, it is > better to pack it up within the class, after all... that is the nature of > Object Oriented Programming. As long as the reference you return exists, no problem. But suppose the object of the class mentioned is destroyed, your string reference will be dangling, yielding undefined results. Of course, as long as you know what youre doing, youre fine. But I wouldnt advice people, specially novices, doing that sort of function. Just MHO. ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Dev-cpp-users mailing list Dev...@li... TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm https://lists.sourceforge.net/lists/listinfo/dev-cpp-users |