GCC compile problem ...

gcc@wiesinger.com gcc@wiesinger.com
Fri Sep 27 09:09:00 GMT 2002


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
        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++


More information about the Gcc-help mailing list