C++ const double pointer
C++ const double pointer
我想使恒定的双指针指向恒定指针指向恒定双重指针。我开始做到这一点(当然,我在书本上进行了一些搜索,并从头开始搜索了它),然后思考以下三种做法:
const double* cp; //pointer to a constant double
double *const cp; //constant pointer
const double *const cp; //constant pointer to a constant double
我认为下一步是写一个常量的双指针
double **const cp;// double constant pointer
然后我结合了最后两个语句,然后写
const double *const cp = arr[0];
double **const cp1 = arr ;
其中ARR是动态分配的双维数组。之后,我尝试验证我的所作所为,并写了以下陈述,期望产生错误。
**cp1 = 1; // didn't produce error
*cp1 = arr[4]; // didn't produce error
cp1 = new double*[5]; //produce error
所以我无法制作上面描述的内容,一个恒定的双指针指向一个恒定的指针指向恒定的双重双重指针。我该怎么做?
预先感谢。
中只有一个
const
double **const cp1 = arr ;
// ^^^^^
所以我不确定为什么您期望其他两个作业会产生错误。
如果您希望它是所有级别的const
,则需要
const double *const *const cp1 = arr;
// ^ cp1 is ...
// ^ a const pointer to ...
// ^ a const pointer to ...
// ^ a const double
相关文章:
- C++ - "!pointer"和"pointer == nullptr"的区别?
- C++在数学计算中将double转换为int
- 在c++中为double类型的数组创建一个unique_ptr
- vector<vector<double>> to mxArray using memcpy
- (double) 和 double() 之间的区别
- C++标准是否允许<double>在没有开销的情况下实现 std::可选
- C++ Version Of Double.longBitsToDouble
- 错误:类型"double()"和"double()"的操作数无效到二进制&quo
- 有没有办法在C++的赋值中将"char**"转换为"double"?
- 为什么 nlohmann/json 序列化 "null" 而不是在 double 上"0"?
- 使用 std::vector<double> 访问由 std::unique_ptr<double[2] 管理的数据>
- 将 std::vector<double> 从 C++ 包装到 C 以在 Swift 中使用
- 错误:无法将"<lambda(double)>"转换为"double(*)(double)"
- "No-Const Pointer to Const "调用功能
- "owned pointer"和 std::shared_ptr 的"stored pointer"有什么区别?
- 如何正确将"strings"转换为"double"?
- 删除分配的 (?) 指针时"Pointer being freed was not allocated"
- 如何在<double>矢量中创建复杂类型的模板<T>?
- C++ const double pointer
- MPI_Send double pointer