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: Jamiil A. <jal...@gm...> - 2007-07-23 00:35:32
|
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.
----- Original Message -----
From: "matheus ribeiro" <mfr...@gm...>
Cc: <dev...@li...>
Sent: Sunday, July 22, 2007 5:25 PM
Subject: Re: [Dev-C++] How would you write a method returning a string ?
> The first question to ask is: why would one need that? C++ strings
> were made thinking of them as a base value, like int.
>
> Id rather write a function with
>
> const std::string somefunction(const char *val)
>
> prototype.
>
> 2007/7/22, Jamiil Abduqadir <jal...@gm...>:
>> And how would you suggest one should write a method that receives a
>> 'const
>> char*' and returns a 'std::string&'?
>>
>>
>>
>> ----- Original Message -----
>> From: "matheus ribeiro" <mfr...@gm...>
>> To: <dev...@li...>
>> Sent: Sunday, July 22, 2007 8:45 AM
>> Subject: Re: [Dev-C++] How would you write a method returning a string ?
>>
>>
>> >> std::string& NameSpace::ClassName::MethodName(const char* var){return
>> >> someString = var;}
>> >
>> >
>> > Not a good idea if somestring is a function variable. It will go out
>> > of scope and be destroyed, returning a ref to it will yield undefined
>> > results.
>> >
>> > -------------------------------------------------------------------------
>> > 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
>>
>>
>> -------------------------------------------------------------------------
>> 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
>>
>
> -------------------------------------------------------------------------
> 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
|