gpt4 book ai didi

c++ - 尝试初始化 MFC CCriticalSection 时出现错误 C2248

转载 作者:太空宇宙 更新时间:2023-11-04 14:13:54 30 4
gpt4 key购买 nike

为此,我已经尝试修复/寻找一个小时左右的解决方案。基本上我有:

CCriticalSection pCS;

在类声明中,然后我像这样使用 CSingleLock:

CSingleLock pSL(&pCS);
pSL.Lock();
*Stuff happening here*
pSL.Unlock();

锁定和解锁 pCS。但是初始化 CriticalSection 似乎总是这样结束:

c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxmt.h(82): error C2248: 'CObject::operator =' : cannot access private member declared in class 'CObject'
c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afx.h(535) : see declaration of 'CObject::operator ='
c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afx.h(509) : see declaration of 'CObject'
This diagnostic occurred in the compiler generated function 'CSyncObject &CSyncObject::operator =(const CSyncObject &)'

我在程序中有 4 个工作线程,我向它们发送指向 CCriticalSection 所在类的指针,这些线程在 CCriticalSection 以及主线程上工作。线程使用类的指针来使用使用 CCriticalSection 的 CSingleLock。

供您引用,该代码还包括 Direct2D,但这应该无关紧要。

一些帮助将不胜感激。

编辑:

刚刚尝试创建一个新项目:

#include <afxmt.h>

在里面。它给了我异常(exception)。那是正常的吗?我使用的是 VC++ 2010 Professional。

已解决:

那里也有一个 CEvent,所以我想我也会把它变成一个指针,你知道吗?它解决了那个问题。现在有一个 afxmt.h 文件给我异常。

最佳答案

如果您希望多个线程在 CRITICAL_SECTION 上同步,您可以共享一个指向同一临界区的指针,但实际上不能复制 CRITICAL_SECTION。

关于c++ - 尝试初始化 MFC CCriticalSection 时出现错误 C2248,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12754784/

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