I have a base class, and I do not want to make derived class copyable. In order to make everything explicit I implement it in that way:
class A {
public:
A() = default;
virtual ~A() = default;
A(const A&) = delete;
A(const A&&) = delete;
A& operator=(const A&) = delete;
A& operator=(const A&&) = delete;
virtual void vFun() = 0;
};
class B : public A {
public:
B() = default;
virtual ~B() = default;
B(const B&) = delete;
B(const B&&) = delete;
B& operator=(const B&) = delete;
B& operator=(const B&&) = delete;
virtual void vFun() override {}
};
Is this correct way of doing such things? According to my knowledge and what I have read, the answer is yes, but I would like to be sure before I introduce it into production system.
Taking things into conclusion: 1) Almost always move operators should not be deleted. That's because "there's an infinity of things that require movability". 2) For abstract base class, it's safer to allow compiler to generate special member function, and move deletion into derived class if such necessity exists.
An alternative to “The Rule of The Big Four (and a half)” has appeared in the form of “The Rule of Zero”. “The Rule of Zero” basically states: You should NEVER implement a destructor, copy constructor, move constructor or assignment operators in your code.
Therefore, it is proven that any number or expression raised to the power of zero is always equal to 1. In other words, if the exponent is zero then the result is 1. The general form of zero exponent rule is given by: a 0 = 1 and (a/b) 0 = 1. 0° = undefined.
So 2 to the zero power is going to be equal to 1. And, actually, any non-zero number to the 0 power is 1 by that same rationale.
Answer: 4 to the power of 0 is 1. According to the zero property of exponents, any number (other than 0) raised to the power of zero is always equal to 1. So, 4 to the power of 0 can be written as 40 which is equal to 1.
Nope, this is completely incorrect.
Firstly, in your quest to make the derived class noncopyable, you have made it non-movable, which renders it nearly useless.
Secondly, there's no reason for A to be noncopyable at all. Each derived class can just make itself noncopyable if it wants to. A is already abstract and cannot be sliced so there's no reason to make A noncopyable.
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