声明类型没有任何可变类型
decltype without any variable type
我对C 中的声明使用情况并不那么经验。但是以下是我最终出于项目目的到达的代码:
#include <iostream>
#include <inttypes.h>
#define SA(obj) ((obj)->u)
struct A
{
A()
{
std::cout << "Called" << std::flush << std::endl;
}
uint32_t u;
};
int main()
{
struct A a2;
decltype(A().u) p;
a2.u = 99;
p = a2.u;
if(a2.u != SA(&a2) )
std::cout << "Not Same" << std::flush << std::endl;
else
std::cout << "Same" << std::flush << std::endl;
}
我可以看到A的构造函数仅称为以下语句的原因:
struct A a2;
同样关心的是,该构造中的构造是什么意思 - 它不会创建结构的临时实例 -
decltype(A().u) p;
如下声明给出了汇编错误:
decltype(A.u) p;
c++ -std=c++11 try5.cpp
try5.cpp: In function 'int main()':
try5.cpp:18:17: error: invalid type in declaration before ';' token
decltype(A.u) p;
decltype
括号内的表达式未评估。编译器仅分析了发现其类型,但从未转换为实际可执行代码。
A.u
失败了分析阶段,因为您不能在类型名称之后使用.
。
相关文章:
- 了解类型是否可调用
- 检查模板中 nullptr 的函数指针,了解任何类型的可调用对象
- 当前不会命中断点。没有调试器目标代码类型的可执行代码与此文件关联
- 键入特征以检查类型是否可从流和 MSVC 读取
- 具有不同类型的可选参数的调用方函数
- 在C++中获取命名空间名称的任何可移植技巧
- 如何从 pjsip 发送电子邮件.是否有任何可用于发送电子邮件的默认方法
- 哪种类型特征表明该类型是可分配的?(元组,对)
- C 功能接受给定模板签名的任何可呼叫
- 为什么 std::vector 允许对其包含的类型使用可抛出的移动构造函数?
- 模板类型是否可选使用?
- 如何在观察器中处理具有不同状态值类型的可观察量
- 如何正确使用带有公共成员变量的类型 boost::可选?
- 检查变量类型是否可迭代?
- 如果包含的类型是可简单复制的类型,则 std::Optional 是否为可平凡复制的类型
- 重载运算符:常量与非常量返回类型:任何性能差异
- C++ 模板类/类型,可在最大值和最小值之间进行选择
- std::引用类型的可选专用化
- std::函数,返回任何可求和类型
- 如何将任何可迭代类型作为函数参数传递