Z
zade
codes like below:
// [[code begin]]
class Foo{
public:
int i;
Foo& operator=(const Foo&){
return *this;
}
};
void func(Foo&){
}
void test(){
func(Foo() = Foo()); // compile ok
func(Foo()); // compile error
}
// [[code end]]
Foo() generate a temporary object, which is a const reference object in c++. so why func(Foo() = Foo()) compile ok but func(Foo()) compile error.
// [[code begin]]
class Foo{
public:
int i;
Foo& operator=(const Foo&){
return *this;
}
};
void func(Foo&){
}
void test(){
func(Foo() = Foo()); // compile ok
func(Foo()); // compile error
}
// [[code end]]
Foo() generate a temporary object, which is a const reference object in c++. so why func(Foo() = Foo()) compile ok but func(Foo()) compile error.