Puzzled by const string& parameter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am using GCC 4.0 on FC4.

Here is my problem.

I have a test function:

void test(string& s)
{
}

I can call this function with a string var:
string s("abc");
test(s);

But I cannot do this:
test(string("abc"));

But MS C/C++ compiler (Visual C++ Toolkit) compiles the above code with no problem.

I thought it was acceptable - but it is not.

However, if I declare the parameter to be const, like this:
void (const string& s)

Then I can do test(string("abc")) and EVEN test("abc")!

I *tried* to read through the C++ standard draft, but did not get any anwsers out of it.

Please somebody explain why. Thanks.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux