casting A* to A& ?

G

Guest

int i;
(char) i;

I am sure it is an rvalue. Just try this:
int i;
(char) i = 123; // error

However, on non-builtin types it is indeed an lvalue:
struct A { A(int) {} };

int i;
(A)i = (A)4;

The result is a temporary lvalue.

So, builtin types do not instantiate but classes do?
 
D

Doug Harrison [MVP]

Pieter de Goeje said:
int i;
(char) i;

I am sure it is an rvalue. Just try this:
int i;
(char) i = 123; // error

However, on non-builtin types it is indeed an lvalue:
struct A { A(int) {} };

int i;
(A)i = (A)4;

The result is a temporary lvalue.

No. Temporary objects are rvalues. I don't know if it's possible to define
the terms lvalue and rvalue WRT C++ except to list those things the standard
says they are; a more abstract definition eludes me. I once posted this as
an example of a sort of built-in joke:

*****

http://groups.google.com/[email protected]

struct X
{
};

void g(X&);

void f()
{
X() = X();

g(X() = X());

g(X()); // No good
}

Note that above, the result of assigning one rvalue to another rvalue
is a modifiable lvalue. :)

*****

The difference between the rvalues produced by X() and int() is that the
former has member functions you can call on it, and you're allowed to call
them, including the assignment operator.
So, builtin types do not instantiate but classes do?

I don't get the question.
 
I

Igor Tandetnik

Doug Harrison said:
I don't get the question.

It's a reference to Sigurd Stenersen's insistence that some instances of
C-style cast expression are "real" casts, and others are kinda sorta not
really casts but, you know, "instantiations" - a position that got
everyone baffled for a while. You'll have to read the whole thread to
understand this fine point. It's not really all that interesting.
--
With best wishes,
Igor Tandetnik

"On two occasions, I have been asked [by members of Parliament], 'Pray,
Mr. Babbage, if you put into the machine wrong figures, will the right
answers come out?' I am not able to rightly apprehend the kind of
confusion of ideas that could provoke such a question." -- Charles
Babbage
 
S

Sigurd Stenersen

Pieter said:
I am sure it is an rvalue. Just try this:
int i;
(char) i = 123; // error

Yes. So this is obviously a cast and not an instantiation.

However, on non-builtin types it is indeed an lvalue:
struct A { A(int) {} };

int i;
(A)i = (A)4;

The result is a temporary lvalue.

Yes. And here you're not casting, you're instantiating. Twice.
 
S

Sigurd Stenersen

Igor said:
It's a reference to Sigurd Stenersen's insistence that some instances
of C-style cast expression are "real" casts, and others are kinda
sorta not really casts but, you know, "instantiations"

That is almost correct. Except when you *do* instantiate you're *not using*
a "C-style cast expression". It just looks kinda similar.

a position that got everyone baffled for a while.

Whoo-hoo !

I managed to make a lot of highly skilled people stop and think for a while.
That's quite an achievement.

Thank you so much for pointing that out, you just made my day.

You'll have to read the whole
thread to understand this fine point.

That's a statement about you.

It's not really all that interesting.

That's another statement about you.
 

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

Top