Due to the project I'm working on, I'm required to use a GCC compiler. The problem is, it's giving me some strange errors when compiling the code I've written in MSVC.
Like, for example, if I had a function that took a STL string reference and I passed a type casted char string, GCC would give me errors. This code would work fine in MSVC.
Here's some pseudo to illustrate what I'm talking about:
1 2 3 4 5 6 7 8 9 10 11
void OutputString(std::string & myString)
{
//...
}
int main()
{
char * myCharString = "Hello World!";
OutputString((std::string)myCharString); //Works fine in MSVC, errors in GCC
return 0;
}
It seems as though type casting doesn't return a value in GCC. Could anyone explain this?
Also, I'd like to hear your recommendations for a GCC IDE.
invalid initialization of non-const reference of type 'std::string&' from a temporary of type 'std::string'
It something about the lifetime of the object.
The temporaries die in that line, but you can extend the life with a const reference. However you are using a non-const reference, requiring a lvalue.
i wonder why it compiles in MSVC.
Also:
1 2
//char * myCharString = "Hello World!"; //deprecated conversion from string constant to 'char*'
constchar *myCharString = "Hello World!";
error: invalid initialization of non-const reference of type 'std::string&' from a temporary of type 'std::string'
error: in passing argument 1 of 'void OutputString(std::string&)'
And I didn't bump because it was taking too long, I bumped because it got moved half way down the page. :)