C++ Net 不识别NULL,该怎么办呢?
我写了一个 C++net访问数据的单例模式:
//头文件:
ref class DBAccess
{
private:
SqlConnection ^ conn;
SqlCommand ^ comm;
static DBAccess ^ access;
DBAccess(void);
public:
bool initialDB();
static DBAccess^ getInstance();
};
//源文件:
DBAccess::DBAccess(void) //私有构造函数
{
conn = gcnew SqlConnection();
comm = gcnew SqlCommand();
if (!initialDB())
{
MessageBox::Show("数据库初始化失败!");
}
}
bool DBAccess::initialDB()
{
conn->ConnectionString = "data source=.;database=FundSystem; uid=sa;pwd=sa";
comm->Connection = conn;
try
{
conn->Open();
}
catch (System::Exception ^e)
{
return false;
}
return true;
}
DBAccess^ DBAccess::getInstance()
{
if (access == null) {
access = gcnew DBAccess();
}
return access;
}
报错:DBAccess.cpp(38) : error C2065: “null”: 未声明的标识符
------解决方案--------------------------------------------------------
==nullptr