Monday, October 29, 2012

error C2259: “CException”: 不能实例化抽象类

因为VS6后的CException改得太多了,我们只能配合形势.将看Exception的源码:

 

class AFX_NOVTABLE CException : public CObject
{
// abstract class for dynamic type checking
DECLARE_DYNAMIC(CException)

public:
// Constructors
CException(); // sets m_bAutoDelete = TRUE
explicit CException(BOOL bAutoDelete); // sets m_bAutoDelete = bAutoDelete

// Operations
void Delete(); // use to delete exception in 'catch' block

virtual BOOL GetErrorMessage(_Out_z_cap_(nMaxError) LPTSTR lpszError, _In_ UINT nMaxError,
_Out_opt_ PUINT pnHelpContext = NULL) const ;
virtual BOOL GetErrorMessage(_Out_z_cap_(nMaxError) LPTSTR lpszError, _In_ UINT nMaxError,
_Out_opt_ PUINT pnHelpContext = NULL);
virtual int ReportError(UINT nType = MB_OK, UINT nMessageID = 0);

// Implementation (setting m_bAutoDelete to FALSE is advanced)
public:
virtual ~CException() = 0;
BOOL m_bAutoDelete;
#ifdef _DEBUG
void PASCAL operator delete(void* pbData);
void PASCAL operator delete(void* pbData, LPCSTR lpszFileName, int nLine);
protected:
BOOL m_bReadyForDelete;
#endif
};




改成下表给出了MFC 提供的预定义异常:


CMemoryException:内存不足


CFileException:文件异常


CArchiveException:存档/序列化异常


CNotSupportedException:响应对不支持服务的请求


CResourceException:Windows 资源分配异常


CDaoException:数据库异常(DAO 类)


CDBException:数据库异常(ODBC 类)


COleException:OLE 异常


COleDispatchException:调度(自动化)异常


CUserException:用消息框警告用户然后引发


问题2:以一种访问权限不允许的方式做了一个访问套接字的尝试


解决:关闭WINDOWS7的账户控制. 比如:在开始菜单下输入UAC,弹出用户权限控制. 把它拖到最底的选项.

No comments: