我遇到了以下一段代码,但我无法理解它的含义:
typedef int INT;
5 .INT::~INT();
注意:数字 5 和小数之间有一个空格。
问题:
1. 有人能解释一下上面两行到底是什么意思吗?
2. 为什么没有 typedef 就不行?背后有什么原因吗?5 .int::~int()
抛出错误。
最佳答案
.INT::~INT()
是一个伪析构函数调用,对模板化代码很有用。
注意,没有typedef
类型是不能使用的。
标准:
C++03 §5.2.4 “伪析构函数调用”:
- The use of a pseudo-destructor-name after a dot
.
or arrow->
operator represents the destructor for the non-class type named by type-name. The result shall only be used as the operand for the function call operator()
, and the result of such a call has typevoid
. The only effect is the evaluation of the postfix-expression before the dot or arrow.
关于c++ - 原始类型作为 C++ 中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32668828/