-2

Can somebody explain me why in VC++ 12 string &s = string("this"); works but not int &d = int(10); what operators are called while initializing a non const reference.

Thanks.

1 Answers1

2

False premise: string &s = string("this"); is not valid C++. Lvalue references cannot bind to rvalues.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
  • ok, now that was the reason I asked, should improve the question. It compiles for me in VC++ 12 compiler. I would like to know why? – code_not_yet_complete May 27 '15 at 08:57
  • @code_not_yet_complete: Because VC++ is not a C++ compiler, but the root of all evil :-) I'm very sorry for your loss. If you like to be industry-competitive (and employable) at C++, I recommend always cross-checking your code with a second compiler, e.g. Clang or GCC. – Kerrek SB May 27 '15 at 09:07
  • 1
    If a non-standard extension makes VC++ not a C++ compiler, then there are no C++ compilers. – Benjamin Lindley May 27 '15 at 09:11
  • @KerrekSB thanks for the reply. Can you probably tell me why it does not work for int ? – code_not_yet_complete May 27 '15 at 09:15