This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]