- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想使用 std::add_pointer<type>
来自 C++ 的模板 <type_traits>
header 构造一个指向数组类型的指针。
但是,下面会产生错误
double *y[2];
std::add_pointer<double[2]>::type x;
y = x; // generates error
我的 MSVC C++ 编译器附带 SDK 7.1 说
error C2440: '=' : cannot convert from 'double (*)[2]' to 'double *[2]' There are no conversions to array types, although there are conversions to references or pointers to arrays
我在这里错过了什么?
编辑:我希望 y 是一个二维数组,一维为 2,另一个为变量。预期用途是
y[i][0]
和 y[i][1]
最佳答案
y
和 x
在这里没有相同的类型。
如错误消息所述,y
是一个元素类型为 double*
的数组。 x
是指向类型为 double[2]
的数组的指针。
您可以将 y
的类型更改为:
double (*y)[2];
std::add_pointer<double[2]>::type x = new double[2][2];
y = x;
// use y[0][0], y[0][1], y[1][0] ...
delete[] y;
关于具有数组类型的 C++ add_pointer 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36714090/
我刚刚发现 C++ 11 中存在 std::add_pointer 。我查看了以下链接中的文档,但我并没有真正理解这样一个对象的目的: http://www.cplusplus.com/referen
我想使用 std::add_pointer来自 C++ 的模板 header 构造一个指向数组类型的指针。 但是,下面会产生错误 double *y[2]; std::add_pointer::ty
在 cppreference add_pointer ,据说我们可以将其实现为: namespace detail { template struct type_identity { using t
这个问题是A question regarding the implementation of std::add_pointer的后续问题 下std::add_pointer 有如下引用: Other
来自 std::add_pointer Possible implementation namespace detail { template struct type_identity { usin
我是一名优秀的程序员,十分优秀!