This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
GCC compile problem ...
- From: gcc at wiesinger dot com
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 27 Sep 2002 18:09:07 +0200 (CEST)
- Subject: GCC compile problem ...
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
// works well: string s = test.getString();
cout << s << "\n";
// 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