gpt4 book ai didi

c++ - 原始类型作为 C++ 中的对象

转载 作者:IT老高 更新时间:2023-10-28 21:52:58 25 4
gpt4 key购买 nike

我遇到了以下一段代码,但我无法理解它的含义:

typedef int INT; 
5 .INT::~INT();

注意:数字 5 和小数之间有一个空格。

问题:1. 有人能解释一下上面两行到底是什么意思吗?2. 为什么没有 typedef 就不行?背后有什么原因吗?5 .int::~int() 抛出错误。

最佳答案

.INT::~INT() 是一个伪析构函数调用,对模板化代码很有用。

注意,没有typedef类型是不能使用的。


标准:

C++03 §5.2.4 “伪析构函数调用”:
  1. 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 type void. The only effect is the evaluation of the postfix-expression before the dot or arrow.

关于c++ - 原始类型作为 C++ 中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32668828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com