protocol7::CNetEvent_Damage *pEvent7 = (protocol7::CNetEvent_Damage *)s_aEventStore;
*pSize = sizeof(*pEvent7);
ip link
plsip link
pls 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp5s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether b4:2e:99:96:81:1d brd ff:ff:ff:ff:ff:ff
struct A {
int *test;
[[nodiscard]] virtual int value() const = 0;
A(): test(new int{10}){}
virtual ~A() {};
};
struct B : public A {
[[nodiscard]] int value() const override {
return *test;
}
~B() override {
delete test;
}
};
int main() {
B b;
}
This would work, but is it somehow possible to leak memory? If somehow only A::~A()
is called?
virtual ~A() = 0
sadly does not work. And if I delete test
inside A::~A()
I'll double free test
....
What is the best practice in this situation?std::unique_ptr
frees you from thinking about this at all)static
variable. Improve readability by not nesting post-increment in another statement.
std::unique_ptr
? I am pretty new to Cpp