class B {
int i;
public:
B(int param) : i(param) {}
~B() = delete;
};
class D : public B {
int i2;
public:
D(int p1, int p2) : B(p1), i2(p2) {}
~D() = delete;
};
int main() {
B* instance = new D(1,2);
return 0;
}
cl test.cpp:
Microsoft (R) C/C++ Optimizing Compiler Version 18.00.31101 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
test.cpp
test.cpp(11) : error C2280: 'B::~B(void)' : attempting to reference a deleted function
test.cpp(6) : see declaration of 'B::~B'
(There is one line with an inscription above the code, so this is one of them. Sorry)
I have some special classes (one base and many derivatives) that, for performance reasons, are always allocated on the stack, for example in memory. They do not receive any destructor calls (and they do not need a design). It can be bad if some programmer after me decides that he really needs to put the vector inside. (Memory leaks, these classes are spawned by large numbers and several function calls live, ouch)
I tried using remote C ++ 11 destructors. My questions are:
- Why is this not working?
- Any better ideas on how to disable destructors or non-PODs inside a class?