Implicit parameter declaration question

I have function which takes
void setthis(string &name);

On windows with nmake compilation
setthis(string("henry")) --->works

On Linux
setthis(string("henry")) --> error

Is that a run time error, or a compiler error?
This is because you cannot pass a non-const reference to a temporary object to a function. Change it to:

 
void setthis(const string& name); // make it a const reference 
I know it works with const.
Then how is it compiling in windows.Why I am not getting compile error on windows ?
Is this related to some compile time options
Last edited on
Are you using the same compiler and version? I'm guessing not.
The windows compiler is non-compliant.

Standard says that non-const references cannot be bound to temporaries, as Disch said.
closed account (z05DSL3A)
VS issues it as a level 4 warning
.\test.cpp(9) : warning C4239: nonstandard extension used : 'argument' : conversion from 'std::basic_string<_Elem,_Traits,_Ax>' to 'std::string &'
with
[
_Elem=char,
_Traits=std::char_traits,
_Ax=std::allocator
]
A non-const reference may only be bound to an lvalue
Linking...


One reason why I compile with maximum warnings and treat warnings as errors.

thank you
Last edited on
Topic archived. No new replies allowed.