cv-qualified rvalues

S

Steven T. Hatton

This footnote appears in the section of the Standard specifying lvalue to
rvalue conversion.

(footnote 49)"In C++ class rvalues can have cv-qualified types (because they
are objects). This differs from ISO C, in which non-lvalues never have
cv-qualified types."

I believe I understand the basics of what it's saying. I could have some
class-type object on the right side of an assignment operator. I'm not
completely sure what the significance of it being cv-qualified is. Is this
related to the kind of thing that happens with std::auto_ptr<> when it
changes state if its owned object is assigned away?
 
V

Victor Bazarov

Steven said:
This footnote appears in the section of the Standard specifying
lvalue to rvalue conversion.

(footnote 49)"In C++ class rvalues can have cv-qualified types
(because they are objects). This differs from ISO C, in which
non-lvalues never have cv-qualified types."

I believe I understand the basics of what it's saying. I could have
some class-type object on the right side of an assignment operator.
I'm not completely sure what the significance of it being
cv-qualified is. Is this related to the kind of thing that happens
with std::auto_ptr<> when it changes state if its owned object is
assigned away?

#include <iostream>
struct A {
void foo() const { std::cout << "A::foo() const\n"; }
void foo() { std::cout << "A::foo()\n"; }
};

A bar() { return A(); }
A const cbar() { return A(); }

int main() {
bar().foo(); // calls foo
cbar().foo(); // calls foo const
}

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top