문제

나는 C++에서 코딩을 위해 지난 몇 년이다.그러나 한가지 질문들이지 않았습니다.을 물어보고 싶은 모든 임시 개체에서는 C++,반환?

지 않은 경우,할 수 있는 사람을 나에게 제공 예를 들어 임시에서 생산되는 코드입니다 lvalue?

도움이 되었습니까?

해결책

No.

The C++ language specification never makes such a straightforward assertion as the one you are asking about. It doesn't say anywhere in the language standard that "all temporary objects are rvalues". Moreover, the question itself is a bit of misnomer, since the property of being an rvalue in the C++ language is not a property of an object, but rather a property of an expression (i.e. a property of its result). This is actually how it is defined in the language specification: for different kinds of expressions it says when the result is an lvalue and when it is an rvalue. Among other things, this actually means that a temporary object can be accessed as an rvalue as well as an lvalue, depending on the specific form of expression that is used to perform the access.

For example, the result of literal 2 + 3 expression is obviously an rvalue, a temporary of type int. We cannot apply the unary & to it since unary & requires an lvalue as its operand

&(2 + 3); // ERROR, lvalue required

However, as we all know, a constant reference can be attached to a temporary object, as in

const int &ri = 2 + 3;

In this case the reference is attached to the temporary, extending the lifetime of the latter. Obviously, once it is done, we have access to that very same temporary as an lvalue ri, since references are always lvalues. For example, we can easily and legally apply the unary & to the reference and obtain a pointer to the temporary

const int *pi = &ri;

with that pointer remaining perfectly valid as long as the temporary persists.

Another obvious example of lvalue access to a temporary object is when we access a temporary object of class type through its this pointer. The result of *this is an lvalue (as is always the case with the result of unary * applied to a data pointer), yet it doesn't change the fact that the actual object might easily be a temporary. For a given class type T, expression T() is an rvalue, as explicitly stated in the language standard, yet the temporary object accessed through *T().get_this() expression (with the obvious implementation of T::get_this()) is an lvalue. Unlike the previous example, this method allows you to immediately obtain a non-const-qualified lvalue, which refers to a temporary object.

So, once again, the very same temporary object might easily be "seen" as an rvalue or as an lvalue depending on what kind of expression (what kind of access path) you use to "look" at that object.

다른 팁

Prasoon Saurav already linked a very good clc++ thread. In there, James Kanze explains why the question doesn't really make sense. It boils down to:

  • rvalue-ness is a (boolean) property of expressions - each expression is either an lvalue or an rvalue
  • temporaries are not expressions

For that reason, the question doesn't make sense.

A good example is the following code:

int main() {
  const int& ri = 4;
  std::cout << ri << std::endl; 
}

The temporary int with value 4 is not an expression. The expression ri that's printed is not a temporary. It's an lvalue, and refers to a temporary.

well, that array operator returns a reference, any function that returns a reference could be considered to do the same thing? all references are const, while they can be lvalues, they modify what they reference, not the reference itself. same is true for the *operator,

*(a temp pointer) = val;

I swear I used to use some compiler that would pass temp values to any function that took a reference,

so you could go:

int Afunc()
{
   return 5;
}

int anotherFunc(int & b)
{
    b = 34;
}


anotherFunc(Afunc());

can't find one that lets you do that now though, the reference has to be const in order to allow passing of temp values.

int anotherFunc(const int & b);

anyway, references can be lvalues and temporary, the trick being the reference it's self is not modified, only what it references.

if you count the-> operator as an operator, then temporary pointers can be lvalues, but the same condition applies, its not the temp pointer that would be changed, but the thing that it points to.

An array indexing operation is both a temporary and an lvalue, something like a[10] = 1 is an example of what you're looking for; the lvalue is a temporary, calculated pointer.

짧은 대답:그렇지만,나는 견적 표준 때문에 증명하는 포인트를 필요로 해결하는 모든 종류의 임시오.정의에 의하여 임시는 일생 일대의 문이 하나,그렇게 할당하는 것을 한 것 가난한 스타일에서 최고입니다.

재미있는 대답한다:복사 elision 만들 수 있습(자주)임시 개체와 동일 lvalue 개체입니다.예를 들어,

MyClass blah = MyClass( 3 ); // temporary likely to be optimized out

return MyClass( 3 ); // likely to directly initialize object in caller's frame

편집: 로에 대한 질문이 있는지 여부의 모든 임시체에서 이러한 경우,§12.8/15mentions

사본 작업을 생략할 수 있을 구성하여 임시 개체에 직접 대상의 생략하면 사본

는 것을 나타내는 임시 개체할 수 있는 동일 lvalue.

SharePoint Designer는 워크 플로 디자이너 사용자 인터페이스 (UI)를 통해 사용할 수있는 워크 플로 작업 모음을 제공합니다. SharePoint Designer에 포함 된 워크 플로우 조치의 범위는 그럼에도 불구하고 그럼에도 불구하고 있습니다. 경우에 따라 SharePoint Designer에서 사용할 수있는 기존 워크 플로 조치의 기존 워크 플로 조치로 요구되는 비즈니스 프로세스를 모델링해야 할 수 있습니다.

아래 링크를 살펴볼 수 있습니다.

사용자 정의를 만드는 모범 사례 SharePoint 2010의 활동

유용한 SharePoint 디자이너 사용자 정의 워크 플로 활동. ->이를 사용하면 "보내기 HTTP 파일 첨부 파일이있는 이메일 "->이 활동을 통해 웹 요청을 사용하여 첨부 파일로 전자 메일을 보내는 이메일을 보낼 수 있습니다. Reporting Services 보고서를 실행하고 SPD 워크 플로 내에서 첨부 파일로 전송하는 것은 하나의 예입니다. 요청 URL은 완전히 사용자 정의가 가능하며 워크 플로 변수를 포함 할 수 있습니다. HTTP 및 HTTPS 요청은 모두 지원됩니다. ...에

SharePoint 2010 : Visual Studio 2010을 사용하여 워크 플로 활동 만들기

SharePoint 2010의 사용자 정의 SharePoint 디자이너 활동

사용자 정의 작업을 어떻게 만들 수 있습니까? 워크 플로우의 경우

If no, can anyone provide me an example where temporary produced in the code is an lvalue?

The following code binds a constant reference to a temporary object of type const float created by the compiler:

int i;
const float &cfr = i;

The behaviour is "as if":

int i;
const float __tmp_cfr = i; // introduced by the compiler
const float &cfr = __tmp_cfr;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top