M
Marcelo De Brito
Hi!
I have stumbled upon an interesting feature when passing objects "by
value" to functions. Let's say I have the following class:
class Class1 {
public:
Class1();
~Class1();
};
And I have two functions that deal with objects from that class:
Class1 func1()
{
Class1 x;
return(x);
}
void func2(Class1& aa)
{
}
So, my objective is passing the return value of "func1" as an argument
to "func2", but doing this directly does not work, that is:
func2(func1()); //!ERROR
BUT, if I define the argument of "func2" as a "const Class1&" type --
that is, "func2(const Class1&)" --, then, no error occurs when calling
"func2(func1())".
Why does that happen?
What is the problem with the line "func2(func1())" ?
Thank You!
Marcelo
I have stumbled upon an interesting feature when passing objects "by
value" to functions. Let's say I have the following class:
class Class1 {
public:
Class1();
~Class1();
};
And I have two functions that deal with objects from that class:
Class1 func1()
{
Class1 x;
return(x);
}
void func2(Class1& aa)
{
}
So, my objective is passing the return value of "func1" as an argument
to "func2", but doing this directly does not work, that is:
func2(func1()); //!ERROR
BUT, if I define the argument of "func2" as a "const Class1&" type --
that is, "func2(const Class1&)" --, then, no error occurs when calling
"func2(func1())".
Why does that happen?
What is the problem with the line "func2(func1())" ?
Thank You!
Marcelo