I want class B to inherit all but a few methods of class A (which is assumed to be trivially copyable), and still be trivially copyable. In C++11 I can delete methods. Take for example:
class A { // trivially copyable
// private stuff here
public:
A& operator += (const A&);
// other public stuff here
};
class B: public A {
public:
B& operator += (const A&) = delete;
};
Is B trivially copyable? I know there are issues regarding the deletion of special methods, but the compound assignment is not a special method (right?).
Yes, B
is trivially copyable - regardless of what you do to non-special member functions.
N3337, §9/6:
A trivially copyable class is a class that:
— has no non-trivial copy constructors (12.8),
— has no non-trivial move constructors (12.8),
— has no non-trivial copy assignment operators (13.5.3, 12.8),
— has no non-trivial move assignment operators (13.5.3, 12.8), and
— has a trivial destructor (12.4).
but the compound assignment is not a special method (right?)
No, it's not.
N3337, §12/1:
The default constructor (12.1), copy constructor and copy assignment operator (12.8), move constructor and move assignment operator (12.8), and destructor (12.4) are special member functions.
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