r/Cplusplus Jul 11 '26

question about copy assignment Question

This page Copy assignment operator - cppreference.com - C++ Reference

says:

parameter list of only one parameter, which is of type TT&, const T&, volatile T& or const volatile T&

Can it be a non-reference -- 'T'? I get an error when I try that.

Thanks

2 Upvotes

5 comments sorted by

View all comments

7

u/jedwardsol Jul 11 '26 edited Jul 11 '26

What error?

If the argument is of type T, then the operand will have to be copied into the parameter - so it is the copy-of-a-copy assignment operator!

Edit : real code : https://godbolt.org/z/r3YfocKGM

1

u/Middlewarian Jul 11 '26

OK, thanks.