From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18345 invoked by alias); 27 Sep 2002 16:30:08 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 18254 invoked from network); 27 Sep 2002 16:30:06 -0000 Received: from unknown (HELO smtp.web.de) (194.45.170.210) by sources.redhat.com with SMTP; 27 Sep 2002 16:30:06 -0000 Received: from [129.187.26.10] (helo=mephisto) by smtp.web.de with asmtp (WEB.DE(Exim) 4.75 #2) id 17uy0D-00052f-00 for gcc-help@gcc.gnu.org; Fri, 27 Sep 2002 18:30:05 +0200 Content-Type: text/plain; charset="iso-8859-1" From: Sebastian Huber To: gcc-help@gcc.gnu.org Subject: Re: GCC compile problem ... Date: Fri, 27 Sep 2002 09:30:00 -0000 References: In-Reply-To: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200209271830.15389.sebastian-huber@web.de> X-SW-Source: 2002-09/txt/msg00215.txt.bz2 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 > #include > > using namespace std; > > class Test > { > public: > string getString() { return "hallo"; } > }; > > int main(int argc, char* argv) > { > Test test; > > string& s =3D test.getString(); // Error here This is not ok, because you try to initialize a non-const reference with a= =20 temporary string object. > // works well: string s =3D test.getString(); This is ok, because of the assignment operator looks like: operator=3D( const std::string&) > cout << s << "\n"; This is also ok, because the overloaded shift operator takes a constant=20 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 string_char_traits, __default_alloc_template >' > make[1]: *** [main.o] Error 1 > > Why aren't there references allowed here with gcc? Is this not Ansi C++ > conform? > > Ciao, > Gerhard