gpt4 book ai didi

c++ - 我需要在 Destructor 中删除 CriticalSection 吗?

转载 作者:太空宇宙 更新时间:2023-11-04 16:02:09 28 4
gpt4 key购买 nike

我是 C++ 新手,在我的程序中我有一个具有私有(private)成员 (CRITICAL_SECTION csPtr) 的类。InitializeCriticalSection(&csPtr) 在我的构造函数中调用。我的问题是,我是否需要在析构函数中调用 DeleteCriticalSection(&csPtr)

最佳答案

是的,according to MSDN :

A critical section object cannot be moved or copied. The process must also not modify the object, but must treat it as logically opaque. Use only the critical section functions to manage critical section objects. When you have finished using the critical section, call the DeleteCriticalSection function.

关于c++ - 我需要在 Destructor 中删除 CriticalSection 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41688919/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com