我是 C++ 入门级。尝试构建一个不是我创建的项目。插入一些丢失的库后,我遇到了 C2280 错误:“CBrush::CBrush(const CBrush &)”:试图引用已删除的函数”。我对如何开始深入了解问题感到困惑。
static COLORREF ClrList[] = { RGB(128,0,0), // Red
RGB(128,128,0), // Dark yellow
RGB(0,200,0), // Green
RGB(0,200,200), // Cyan
RGB(0,0,255), // Blue
RGB(125,42,249), // Purple
RGB(255,128,0), // Orange
RGB(0,0,0) }; // Black
static CBrush BrushList[] = { CBrush(ClrList[0]), //Error 2280
CBrush(ClrList[1]),
CBrush(ClrList[2]),
CBrush(ClrList[3]),
CBrush(ClrList[4]),
CBrush(ClrList[5]),
CBrush(ClrList[6]),
CBrush(ClrList[7]) };
CBrush 类声明:
class CBrush : public CGdiObject
{
DECLARE_DYNAMIC(CBrush)
public:
static CBrush* PASCAL FromHandle(HBRUSH hBrush);
// Constructors
CBrush();
CBrush(COLORREF crColor); // CreateSolidBrush
CBrush(int nIndex, COLORREF crColor); // CreateHatchBrush
explicit CBrush(CBitmap* pBitmap); // CreatePatternBrush
BOOL CreateSolidBrush(COLORREF crColor);
BOOL CreateHatchBrush(int nIndex, COLORREF crColor);
BOOL CreateBrushIndirect(const LOGBRUSH* lpLogBrush);
BOOL CreatePatternBrush(CBitmap* pBitmap);
BOOL CreateDIBPatternBrush(HGLOBAL hPackedDIB, UINT nUsage);
BOOL CreateDIBPatternBrush(const void* lpPackedDIB, UINT nUsage);
BOOL CreateSysColorBrush(int nIndex);
// Attributes
operator HBRUSH() const;
int GetLogBrush(LOGBRUSH* pLogBrush);
// Implementation
public:
virtual ~CBrush();
#ifdef _DEBUG
virtual void Dump(CDumpContext& dc) const;
#endif
};
我不熟悉 inl 文件,但我认为这是内联声明:
_AFXWIN_INLINE CBrush::operator HBRUSH() const
{ return (HBRUSH)(this == NULL ? NULL : m_hObject); }
_AFXWIN_INLINE CBrush* PASCAL CBrush::FromHandle(HBRUSH hBrush)
{ return (CBrush*) CGdiObject::FromHandle(hBrush); }
_AFXWIN_INLINE CBrush::CBrush()
{ }
_AFXWIN_INLINE CBrush::~CBrush()
{ }
_AFXWIN_INLINE BOOL CBrush::CreateSolidBrush(COLORREF crColor)
{ return Attach(::CreateSolidBrush(crColor)); }
_AFXWIN_INLINE BOOL CBrush::CreateHatchBrush(int nIndex, COLORREF crColor)
{ return Attach(::CreateHatchBrush(nIndex, crColor)); }
_AFXWIN_INLINE BOOL CBrush::CreateBrushIndirect(const LOGBRUSH* lpLogBrush)
{ return Attach(::CreateBrushIndirect(lpLogBrush)); }
_AFXWIN_INLINE BOOL CBrush::CreatePatternBrush(CBitmap* pBitmap)
{ return Attach(::CreatePatternBrush((HBITMAP)pBitmap->GetSafeHandle())); }
_AFXWIN_INLINE BOOL CBrush::CreateDIBPatternBrush(const void* lpPackedDIB, UINT nUsage)
{ return Attach(::CreateDIBPatternBrushPt(lpPackedDIB, nUsage)); }
_AFXWIN_INLINE BOOL CBrush::CreateSysColorBrush(int nIndex)
{ return Attach(::GetSysColorBrush(nIndex)); }
_AFXWIN_INLINE int CBrush::GetLogBrush(LOGBRUSH* pLogBrush)
{ ASSERT(m_hObject != NULL);
return ::GetObject(m_hObject, sizeof(LOGBRUSH), pLogBrush); }
根据 Microsoft 的文档,您需要为
CBrush
对象添加复制构造函数。
标准 C++ 默认类复制构造函数执行逐个成员的复制。如果您的类的复制构造函数需要但不可用,则私有 CObject 复制构造函数的存在可保证出现编译器错误消息。如果您的类需要此功能,请提供复制构造函数。