struct S {
S() {}
S (const S &) = delete;
};
void f1 (S s) {}
void f2 (S &s) {}
int main() {
S s;
f2(s);
}
Since S(S &s)
is deleted, why does using f2
not throw an error since when it was declared it passes in the arguments S &s
? When I use f1(s)
it throws an error. I've looked at the definition of deleted functions and I thought this would throw an error, but it doesn't. Why?
Because passing by reference doesn't create a copy (which is what f2
uses).
f1
, on the other hand, takes a pass-by-value parameter, which makes a copy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With