Function matching with constructed args

M

Mike Cote

I have the following function call

p->f(G());

where p is a pointer of type P

and a declaration in scope of

void P::f(G& g);

the gcc 3.2 compiler won't match the call to the function.

If I have

G gTmp;
p->f(gTmp);

with the same function declaration in scope
everything works.

Why? 4 other compilers accept it including gcc 2.6.

Is there a gcc 3.2 option to make this work?
 
R

Ron Natalie

Mike Cote said:
p->f(G());
void P::f(G& g);

the gcc 3.2 compiler won't match the call to the function.\

Of course. G() is an rvalue. You can not bind an rvalue to a (non-const)
reference. It would match
void P::f(const G& g);
G gTmp;
p->f(gTmp);

with the same function declaration in scope
everything works.

gTmp is an lvalue.
Why? 4 other compilers accept it including gcc 2.6.

They are broken if they do.
 

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

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top