lvalue

C++ copy constructor syntax: Is ampersand reference to r/l values?

浪尽此生 提交于 2019-12-13 09:04:24
问题 The following is an excerpt from my C++ text, illustrating the syntax for declaring a class with a copy constructor. class Student { int no; char* grade; public: Student(); Student(int, const char*); Student(const Student&); ~Student(); void display() const; }; The copy constructor, as shown here: Student(const Student&); Has an ampersand after the parameter Student. In C, and C++ as-well I believe, the ampersand character is used as a 'address of' operator for pointers. Of course, it is

L-value trouble when using a (void *) as a generic data container

梦想与她 提交于 2019-12-13 03:38:57
问题 Here is a structure used in a program: struct basic_block { void * aux; /* Many other fields, which are irrelevant. */ }; Now: Several instances of basic_block exist during the execution of the program. The program works in stages/passes, which are executed one after another. The aux field is meant for storing stage and basic_block specific data during the execution of a stage, and freed by the stage itself (so the next stage can reuse it). This is why it is a void * . My stage uses aux to

gstreamer sample documentation code not running

一曲冷凌霜 提交于 2019-12-12 03:05:14
问题 Trying to compile and run a sample appsrc code after having successfully executed several tutorials. This is a documentation code, supposed it to run but ... The command used to compile gcc appGuideAppSrc.c -o appGuide `pkg-config --cflags --libs gstreamer-0.10 gstreamer-app-0.10` Got the following error after appGuideAppSrc.c: In function ‘cb_need_data’: appGuideAppSrc.c:14:8: warning: assignment makes pointer from integer without a cast [enabled by default] appGuideAppSrc.c:18:25: error:

What constitutes of RValues?

不问归期 提交于 2019-12-12 03:04:02
问题 RValues are things which are not maniputable regions of memory, so literals like integers are considered RValues. Do constants constitute RValues? const int x = 0; is maniputable at least one time. Now, the temporary objects created by the compiler are also RValues even when they have maniputable memory regions. Why is that so? Because they cannot be modified by "users"? Is this the reason? So, a memory region which is NOT maniputable by the "users" is called RValue? 回答1: Scalar rvalues are

Approved way to avoid lvalue cast warnings and errors?

烂漫一生 提交于 2019-12-12 00:28:00
问题 This is related to JoGusto's answer at Casting Error: lvalue required as left operand of assignment. In the answer, he/she states: but there is one case where it is not true: casting, then dereferencing a pointer: *((int *) chrPtrValue) = some_integer_expression; I think I found the answer at Joseph Mansfield answer from Why does an lvalue cast work?, where he cited the standard. But that confused me more because I can differentiate between lvalues and rvalues , but xvalues and prvalues are

How to copy from primitive type variables when passing through rvalue reference function arguments

妖精的绣舞 提交于 2019-12-11 13:28:22
问题 I can copy from a non-primitive type variable by copy constructor and pass it through rvalue reference function argument. But how can do this with primitive type variables? for example: #include <cassert> #include <iostream> struct MyClass { int m = 0; }; MyClass& f(MyClass& x) { x.m++; return x; } inline MyClass f(MyClass&& x) { return f(x); } int& f(int& x) { x++; return x; } inline int f(int&& x) { return f(x); } int main() { MyClass x1; auto y1 = f(MyClass(x1)); // Calls f(MyClass&&) //

Using a Function returning apointer as LValue

不打扰是莪最后的温柔 提交于 2019-12-11 06:04:22
问题 Why cant I used a function returning a pointer as a lvalue? For example this one works int* function() { int* x; return x; } int main() { int* x = function(); x = new int(9); } but not this int* function() { int* x; return x; } int main() { int* x; function() = x; } While I can use a pointer variable as a lvalue, why can't I use a function returning a pointer as a lvalue? Also, when the function returns a refernce, instead of a pointer, then it becomes a valid lvalue. 回答1: Your first sample

Is *p an lvalue or rvalue

回眸只為那壹抹淺笑 提交于 2019-12-11 05:42:34
问题 In the following code, is *a an rvalue or an lvalue? #include <stdio.h> void main() { int b=2; int *a=NULL; a=&b; *a=3; printf("%d",*a); } 回答1: As exposed in http://en.wikipedia.org/wiki/Value_%28computer_science%29 : Lvalues have memory addresses that are programmatically accessible to the running program (e.g., via some address-of–operator like "&" in C/C++), meaning that they are variables or dereferenced references to a certain memory location. Rvalues can be lvalues (see below) or non

C++ function with reference argument that works for lvalues and rvalues

孤街醉人 提交于 2019-12-11 03:43:08
问题 I would like to have a C++ function which takes an argument, that's a reference, and works for both lvalues and rvalues with the same syntax . Take this example: #include <iostream> using namespace std; void triple_lvalue(int &n) { n *= 3; cout << "Inside function: " << n << endl; } void triple_rvalue(int &&n) { n *= 3; cout << "Inside function: " << n << endl; } int main() { int n = 3; triple_lvalue(n); cout << "Outside function: " << n << endl; triple_rvalue(5); } Output: Inside function: 9

Rvalues in C++03

爷,独闯天下 提交于 2019-12-10 15:35:21
问题 How can you tell whether or not a given parameter is an rvalue in C++03? I'm writing some very generic code and am in need of taking a reference if possible, or constructing a new object otherwise. Can I overload to take by-value as well as by-reference and have the rvalue returns call the by-value function? Or do I have a very sickening feeling that this is why rvalue references are in C++0x? Edit: is_rvalue = !(is_reference || is_pointer) ? 回答1: There apparently is a way to determine