In msvc, I have functions like this and it builds but in gcc it doesnt like it.
void classname::a(std::string &text)
{
stdStringFromClass = text;
}
void classname::b(char *text)
{
a(std::string(text));
}
The issue here is in the &, gcc I think is worried that since I just created that std::string, that passing by reference is risky, so it does not build, but msvc doesnt even warn me.
Why is this incorrect c++ to gcc I keep hearing that msvc is stricter than gcc.
Thanks
The error
AguiWidgetBase.cpp: In member function ‘void AguiWidgetBase::setText(char*)’:
AguiWidgetBase.cpp:91:27: error: no matching function for call to ‘AguiWidgetBase::setText(std::string)’
AguiWidgetBase.cpp:80:6: note: candidates are: void AguiWidgetBase::setText(std::string&)
AguiWidgetBase.cpp:88:6: note: void AguiWidgetBase::setText(char*)
would this be okay?
void classname::a(std::string &text)
{
stdStringFromClass = text;
}
void classname::b(char *text)
{
std::string k = text;
a(k);
}
I have no idea why Visual studio allows you to compile this, but you can’t pass a reference to an anonymous object.
Edit: Its ok for const reference, cause you can pass the temporary object as reference, just being able to modify it doesn’t make sense. That’s why we have rvalue references in C++0x.
Edit2: To your edit, yes that would fix the problem, or just take a const reference as parameter in the
a()method, you don’t seem to modify the parameter.