Похожие чаты

OK ,so @Kenshin_Dark_Knight_Himura Azadi 1. I should I have not

made it pointer, because then i have to worry about the allocation and deallocation of the memory.
2. If I did make it a pointer (and use the compiler defaults), i should define all the 6 special member function explictly, because the compiler generated defaults may not be accurate in case of pointer members.

Right?

2 ответов

13 просмотров

1- That's RAII, allocate your resource in the ctor and release it in the dtor. It's fine and depending upon your class design a pointer or non-pointer may be needed. But the simpler the better and if you can tune out of pointers that would be more recommended as they're quite error prone 'But' if you need them go and use them as they're quite strong. You can also you smart pointers if you're too worried about deallocating the allocated memory.

Yes, this is the gist of the matter. Pointers come with the extra cognitive load of ownership; who owns this resource right now, and who is eventually responsible for it's safe disposable after use. This requires special and critical attention. If you really need the member as a pointer after much analysis, consider one of the myriad of smart pointers the C++ world offers, in and out of the standard. Those raw pointers should really be avoided, except if you are implementing some unique specialized resource handling facility. As for the six special member functions, they have the interesting interaction in which defining one can disable the others, and thus throw your expectations off course. Bermuda Triangle stuff. Hence, if you define one, define them all, for proper and expected operation of your facility, and also for your own sanity.

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта