From: Sebastian Huber <sebastian-huber@web.de>
To: gcc-help@gcc.gnu.org
Subject: Re: GCC compile problem ...
Date: Fri, 27 Sep 2002 09:30:00 -0000 [thread overview]
Message-ID: <200209271830.15389.sebastian-huber@web.de> (raw)
In-Reply-To: <Pine.LNX.4.44.0209271805510.7519-100000@bbs.intern>
Hi!
On Friday 27 September 2002 09:09, gcc@wiesinger.com wrote:
> Hello!
>
> I have the following compile problem with gcc 3.0.4.
>
> Borland C++ 5.5 and Microsoft Visual C++ 6.0 works well.
>
> #include <string>
> #include <iostream>
>
> using namespace std;
>
> class Test
> {
> public:
> string getString() { return "hallo"; }
> };
>
> int main(int argc, char* argv)
> {
> Test test;
>
> string& s = test.getString(); // Error here
This is not ok, because you try to initialize a non-const reference with a
temporary string object.
> // works well: string s = test.getString();
This is ok, because of the assignment operator looks like:
operator=( const std::string&)
> cout << s << "\n";
This is also ok, because the overloaded shift operator takes a constant
reference.
> // gcc --version: 3.0.4
> }
>
> main.cpp: In function `int main (int, char *)':
> main.cpp:17: initialization of non-const reference type `class string
> &'
> main.cpp:17: from rvalue of type `basic_string<char,
> string_char_traits<char>, __default_alloc_template<true, 0> >'
> make[1]: *** [main.o] Error 1
>
> Why aren't there references allowed here with gcc? Is this not Ansi C++
> conform?
>
> Ciao,
> Gerhard
next prev parent reply other threads:[~2002-09-27 16:30 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-09-27 9:09 gcc
2002-09-27 9:30 ` Sebastian Huber [this message]
2002-09-27 9:35 ` John Love-Jensen
2002-09-27 15:52 ` Sebastian Huber
2002-09-30 4:49 ` John Love-Jensen
-- strict thread matches above, loose matches on Subject: below --
2000-01-26 6:51 gcc " Brian J. Dent
2000-01-26 12:10 ` Alexandre Oliva
2000-04-01 0:00 ` Alexandre Oliva
2000-04-01 0:00 ` Brian J. Dent
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200209271830.15389.sebastian-huber@web.de \
--to=sebastian-huber@web.de \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).