Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #19086
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: casting from 'const string' to a 'non-constant string' |
| Date | 2012-10-19 12:55 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <k5rijs$9kn$1@speranza.aioe.org> (permalink) |
| References | <007be9fb-b37a-4fd7-8778-f17994b52fb4@googlegroups.com> |
Rene Ivon Shamberger <arbolone@gmail.com> wrote:
> const std::string&
> someClass::someMethod(){ return some_string = "Bla Bla Bla"; }
> const std::string& myMethod(){
> someClass obj;
> std::string tmp = obj.someMethod(); /// New code
> return temp;
> }
You should always post code that actually *compiles* rather than typing
at as you go. (For instance, the name 'temp' is undeclared there.)
Anyways, I don't see what causes the error message (probably something
you *didn't* write above), but I do know that you are returning a reference
to a temporary, which is erroneous. (Undefined behavior, may cause the
program to crash or misbehave in some othe rway.)
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
casting from 'const string' to a 'non-constant string' Rene Ivon Shamberger <arbolone@gmail.com> - 2012-10-19 05:36 -0700 Re: casting from 'const string' to a 'non-constant string' Juha Nieminen <nospam@thanks.invalid> - 2012-10-19 12:55 +0000 Re: casting from 'const string' to a 'non-constant string' Victor Bazarov <v.bazarov@comcast.invalid> - 2012-10-19 14:42 -0400 Re: casting from 'const string' to a 'non-constant string' Andy Champ <no.way@nospam.invalid> - 2012-10-19 21:43 +0100
csiph-web