在模板类的方法中 *this = NULL 是什么意思?
在模板类中,我找到了表达式 *this = NULL
这样的表达式是什么意思?
下面是它的定义:
TYPE** getPtr()
{
*this = NULL;
return &m_pPtr;
}
其中m_pPtr 是模板类中的类型TYPE*
。
赋值运算符:
// Assignment operator.
TYPE* operator =(TYPE *pPtr) {
if (pPtr == m_pPtr)
return pPtr;
m_pPtr = pPtr;
return m_pPtr;
}
Vishnu。
Inside a templated class, I found the expression, *this = NULL
What does such an expression mean ?
The following is its definition:
TYPE** getPtr()
{
*this = NULL;
return &m_pPtr;
}
where m_pPtr is type TYPE*
in the template class.
Assignment operator:
// Assignment operator.
TYPE* operator =(TYPE *pPtr) {
if (pPtr == m_pPtr)
return pPtr;
m_pPtr = pPtr;
return m_pPtr;
}
Vishnu.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果没有看到实际的代码,很难说出这样的声明的意义是什么。
但它可能会调用重载的赋值运算符。例如:
It's difficult to say what the point of such a statement is without seeing the actual code.
But it will probably be invoking an overloaded assignment operator. e.g.:
它正在尝试将 0 分配给当前对象。它会调用类似的东西
另一种可能性(据我所知)是对象中有一个构造函数,它采用
void*
或类似的类型。然后它会构造一个对象,然后对其进行复制分配。It's attempting to assign 0 to the current object. It will call something like
Another possibility (as far as I know) is that there is a constructor in the object which takes a
void*
or similar type. Then it would construct an object and then copy-assign that.