dimanche 25 juin 2023

Confusion on template copy assignment function

[First of First: Vs2019 on Windows10, only C++11 supported]

I've got confused on template copy assignment function like: enter image description here

I found the specilization version is not working, why it is not equal to copy assignment function? isn't that template function will be "extended" like macro?

Let's add a move constructor like this: enter image description here

I know that a userd-declared move constructor will set the implicit copy assignment function to delete. if the template copy assignment function is not a "REAL" copy assignment function, then why the compiler says:

error C2280: 'TestClass &TestClass::operator =(const TestClass &)': attempting to reference a deleted function
message : compiler has generated 'TestClass::operator =' here
message : 'TestClass &TestClass::operator =(const TestClass &)': function was implicitly deleted because 'TestClass' has a user-defined move constructor

So, How does compiler see on the template copy assignment function? Why it is omitted in the first case but trigger a compiler error in the second case?

Thanks in advance!

I expect the specilization version of template copy assignment function to be identical to copy assignment function.

Aucun commentaire:

Enregistrer un commentaire