`具有多字基本类型的自动变量声明会导致错误

问题描述 投票:0回答:1

是否可以使用auto关键字和多字类型声明变量?

如果不是,为什么不呢?

例如

auto foo = unsigned int{0};

提供以下编译器输出

Clang:

error: expected '(' for function-style cast or type construction

GCC:

error: expected primary-expression before 'unsigned'

c++ c++11 auto
1个回答
0
投票

您可以使用以下任何一种:

auto foo = 0U;
auto foo = (unsigned int)0;
auto foo = static_cast<unsigned int>(0);
© www.soinside.com 2019 - 2024. All rights reserved.