假设我有一个如下所示的类:
class CBase
{
public:
CBase(void){};
~CBase(void){};
Sigintgen m_oSignals;// This is another class variable which i have not defined here.
};
代码开始如下所示:
main()
{
CBasec *ptr = new CBasec();
I would want the following to happen as shown below:
&(ptr->m_oSignals) should be equal to NULL. Can anyone please suggest me how to get this?
&(ptr->m_oSignals) = NULL; //This was tried but compilation errors.
}
高级谢谢您的支持。
你不能声明后,对象始终存在。
Instead you could dynamically allocate the
Sigintgen
when needed, and haveCBase
store a pointer (which can start asnullptr
).Or use
std::optional
.