I thought that when I delete the move constructor in B
then the following code will still compile fine since it should still take the copy constructor to construct B
objects. Why does the compiler now complain. Without the =delete
it did not and called the copy constructor anyway since it was not allowed to provide a default move constructor!)
class B{
public:
B(){}
~B(){}
B & operator=(const B & b){
std::cout << " cannot move -> copy " << std::endl;
return *this;
}
B(const B & v){
std::cout << " cannot move -> copy " << std::endl;
}
// B(B && b) = delete; // uncomment this!
};
int main()
{
B b( B{} );
}
Compiler Output with clang 3.6 (Live code)
main.cpp:27:7: error: call to deleted constructor of 'B'
B b( B{} );
^ ~~~
main.cpp:21:5: note: 'B' has been explicitly marked deleted here
B(B && b) = delete;
^
1 error generated.
Aucun commentaire:
Enregistrer un commentaire