Passing without a link as a reference without a temp variable

I am trying to do the following: call a function that accepts links as parameters without passing "variables", just values. Can't my compiler (gcc) make temporary “variables” to send? It would seem that mvc does this anyway (another person in the project uses it).

I have:

foo(Vector&,Vector&)

Whenever I try to call foo(Vector(1,2,3),Vector(4,5,6)), I getno matching function for call to foo(Vector,Vector); note: candidates are foo(Vector&,Vector&)

What should I do? Why is this not working? Is there some kind of concept that I don't understand?

Thank.

+3
source share
3 answers

Vector(1,2,3)creates temporary, and temporary cannot be attached to the link not const !

So make the parameters constlike:

void foo(const Vector&, const Vector&)

!

+4

const:

foo(const Vector&,const Vector&)

-const l-, l-.

+3

Use links constif you want to pass temporary variables.

+1
source

All Articles