简体   繁体   English

在C ++中从int **到int * volatile *的正确转换顺序

[英]The right cast sequence from int** to int* volatile* in C++

I wanna cast T** to T * volatile * using C++ style cast. 我想使用C ++样式转换将T**T * volatile * Is this right? 这是正确的吗?

using namespace std;
int** p = nullptr;
auto cast_ptr = static_cast<
                    add_pointer_t<
                        add_volatile_t<
                            remove_pointer_t<decltype(p)>>>>(p);

可能更简单:

auto casted_ptr = static_cast<int * volatile *>(p);

Yes. 是。 It is right. 这是正确的。
Here is a simple method to verify. 这是一种简单的验证方法。 This should work with g++. 这应该适用于g ++。

#include <typeinfo>

cout << typeid(p).name() << endl;

And execute it like this: 并像这样执行它:

$ ./a.out | c++filt -t

You will get the follow output: 您将获得以下输出:

int* volatile*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM