lvalue

function template does not recognize lvalue

删除回忆录丶 提交于 2020-02-03 05:48:05
问题 I have a problem in my code Here is simplified version of it : #include <iostream> class A { public : template <class T> void func(T&&)//accept rvalue { std::cout<<"in rvalue\n"; } template <class T> void func(const T&)//accept lvalue { std::cout<<"in lvalue\n"; } }; int main() { A a; double n=3; a.func(n); a.func(5); } I expect the output to be : in lvalue in rvalue but it is in rvalue in rvalue why ?! 回答1: template <class T> void func(T&&) is universal reference forwarding reference . To

C error: lvalue required as unary '&' operand

房东的猫 提交于 2020-01-12 23:15:48
问题 I have a code error but not sure what's wrong with my casting and reference. BOOL xMBPortSerialPutByte( CHAR ucByte ) { CDC_Send_DATA(&((unsigned char)ucByte), 1); // code error here xMBPortEventPost(EV_FRAME_SENT); return TRUE; } The CDC_Send_DATA is defined as the following: uint32_t CDC_Send_DATA (uint8_t *ptrBuffer, uint8_t Send_length); Here is the error message: port/portserial.c:139:19: error: lvalue required as unary '&' operand Hope someone could help. Thanks! 回答1: The cast operation

C error: lvalue required as unary '&' operand

会有一股神秘感。 提交于 2020-01-12 23:15:27
问题 I have a code error but not sure what's wrong with my casting and reference. BOOL xMBPortSerialPutByte( CHAR ucByte ) { CDC_Send_DATA(&((unsigned char)ucByte), 1); // code error here xMBPortEventPost(EV_FRAME_SENT); return TRUE; } The CDC_Send_DATA is defined as the following: uint32_t CDC_Send_DATA (uint8_t *ptrBuffer, uint8_t Send_length); Here is the error message: port/portserial.c:139:19: error: lvalue required as unary '&' operand Hope someone could help. Thanks! 回答1: The cast operation

One VS2010 bug ? Allowing binding non-const reference to rvalue WITHOUT EVEN a warning?

时光总嘲笑我的痴心妄想 提交于 2020-01-08 13:27:30
问题 string foo() { return "hello"; } int main() { //below should be illegal for binding a non-const (lvalue) reference to a rvalue string& tem = foo(); //below should be the correct one as only const reference can be bind to rvalue(most important const) const string& constTem = foo(); } GCC is the good one to give a compile error : invalid initialization of non-const reference of type std::string& from a temporary of type std::string VS2008 is not too bad as at least it gives a compile warning :

One VS2010 bug ? Allowing binding non-const reference to rvalue WITHOUT EVEN a warning?

自闭症网瘾萝莉.ら 提交于 2020-01-08 13:26:49
问题 string foo() { return "hello"; } int main() { //below should be illegal for binding a non-const (lvalue) reference to a rvalue string& tem = foo(); //below should be the correct one as only const reference can be bind to rvalue(most important const) const string& constTem = foo(); } GCC is the good one to give a compile error : invalid initialization of non-const reference of type std::string& from a temporary of type std::string VS2008 is not too bad as at least it gives a compile warning :

One VS2010 bug ? Allowing binding non-const reference to rvalue WITHOUT EVEN a warning?

荒凉一梦 提交于 2020-01-08 13:26:47
问题 string foo() { return "hello"; } int main() { //below should be illegal for binding a non-const (lvalue) reference to a rvalue string& tem = foo(); //below should be the correct one as only const reference can be bind to rvalue(most important const) const string& constTem = foo(); } GCC is the good one to give a compile error : invalid initialization of non-const reference of type std::string& from a temporary of type std::string VS2008 is not too bad as at least it gives a compile warning :

One VS2010 bug ? Allowing binding non-const reference to rvalue WITHOUT EVEN a warning?

[亡魂溺海] 提交于 2020-01-08 13:26:45
问题 string foo() { return "hello"; } int main() { //below should be illegal for binding a non-const (lvalue) reference to a rvalue string& tem = foo(); //below should be the correct one as only const reference can be bind to rvalue(most important const) const string& constTem = foo(); } GCC is the good one to give a compile error : invalid initialization of non-const reference of type std::string& from a temporary of type std::string VS2008 is not too bad as at least it gives a compile warning :

binding a lvalue expression of type T&&

霸气de小男生 提交于 2020-01-05 07:06:15
问题 In the last few days I've been trying to grasp an apparently trivial principle behind lvalue/rvalue references. Let us define a new rvalue reference: int&& x = 12; x is therefore an lvalue expression of type int&& . Since x is a lvalue, it can be bound to a lvalue reference of the same type, i.e., a lvalue reference of type int&& . Such a lvalue reference would be defined as: int&& & ref_x = x; // non-working code, just for the sake of explanation Of course, it is not possible to explicitly

Does a Comparison Between an Lvalue and a Literal Invoke an Lvalue-to-Rvalue Conversion?

不打扰是莪最后的温柔 提交于 2020-01-02 08:33:08
问题 I asked this question: static_assert of const Variable And apparently it comes down to the question does a floating point lvalue get converted to an rvalue for the purposes of comparison? So in this code does an lvalue-to-rvalue conversion occur? const float foo = 13.0F; static_assert(foo > 0.0F, "foo must be greater than 0."); 回答1: Yes, it is performed. Basically, it's all because 3.0 > 1.2 is a well-formed expression, that contains nothing but prvalues for operands. First, [expr]/9 states

error: 'Int' is not convertible to '@lvalue Float'

≯℡__Kan透↙ 提交于 2020-01-02 05:37:25
问题 Given the following function: func greatestCommonDenominator(first: Int, second: Int) -> Int { return second == 0 ? first : greatestCommonDenominator(second, first % second) } And a struct with the following stuff in it: struct Fraction { var numerator: Int var denominator: Int func reduce() { let gcd = greatestCommonDenominator(numerator,denominator) self.numerator /= gcd self.denominator /= gcd } // stuff } I'm getting the following error: error: 'Int' is not convertible to '@lvalue Float'