Why is the 'this' keyword not a reference type in C++
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicates:
Why ‘this’ is a pointer and not a reference?
SAFE Pointer to a pointer (well reference to a reference) in C#
C++中的EDCOX1×0 }关键字得到指向当前对象的指针。
我的问题是,为什么
我最近的想法是在一个静态函数中,但是VisualC++至少是足够聪明的,可以发现并报告EDCOX1 4。这在标准中吗?
参见stroustrup的"为什么
Because"this" was introduced into C++ (really into C with Classes) before references were added. Also, I chose"this" to follow Simula usage, rather than the (later) Smalltalk use of"self".
因为引用直到后来才添加到C++中。到那时,改变它已经太晚了。
(可能不是一个完整的答案)当一个对象需要用"危险"删除自己时,总是会出现这种情况。
1 | delete this; |
所以它可能是一个指针。
M