由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - a pointer to a const addr
相关主题
question about const reference有关objec access path的问题
C++ Q05: pointer to constant variableC++ 的 问题
谁给解释一下这个c question[合集] 请问-fno-implicit-templates的用处
问一个 char * 和 char [] 的问题不用头文件,如何调用函数?C++
请教一道C语言的题目(面试题) 给code挑毛病(updated with multiple choices)
Go adopts JavaScript’s idea of semicolon insertionwhich style do you prefer?
How to initialize object in constructor?conversion between const to nonconst
is this behavior undefined?关于const_cast,地址一样,值不同?
相关话题的讨论汇总
话题: const话题: double话题: addr话题: pointer话题: pc
进入Programming版参与讨论
1 (共1页)
g*********s
发帖数: 1782
1
is the output undefined? how to initialize this array?
const double* pc = new double[10];
cout << (*pc) << endl;
a***y
发帖数: 2803
2
为什么要const? 没见过这么搞的.

【在 g*********s 的大作中提到】
: is the output undefined? how to initialize this array?
: const double* pc = new double[10];
: cout << (*pc) << endl;

G****A
发帖数: 4160
3
Suppose the default value is 0.
there are two ways (as far as I know) to handle that:
1. const double* pc = new double [SIZE]();
2. std::vector vec(SIZE, 0); --if a vector is working for your
case.

【在 g*********s 的大作中提到】
: is the output undefined? how to initialize this array?
: const double* pc = new double[10];
: cout << (*pc) << endl;

t****t
发帖数: 6806
4
as far as i know, the first is not a valid c++ statement.

【在 G****A 的大作中提到】
: Suppose the default value is 0.
: there are two ways (as far as I know) to handle that:
: 1. const double* pc = new double [SIZE]();
: 2. std::vector vec(SIZE, 0); --if a vector is working for your
: case.

G****A
发帖数: 4160
5
I learned this trick from the following source:
http://stackoverflow.com/questions/2204176/how-to-initialise-me
t****t
发帖数: 6806
6
great! i learned something. thanks for pointing it out.

【在 G****A 的大作中提到】
: I learned this trick from the following source:
: http://stackoverflow.com/questions/2204176/how-to-initialise-me

1 (共1页)
进入Programming版参与讨论
相关主题
关于const_cast,地址一样,值不同?请教一道C语言的题目
why copy assignment operator returns non-const type?Go adopts JavaScript’s idea of semicolon insertion
Undefined symbols for architecture x86_64: 求助How to initialize object in constructor?
一个诡异的const_cast问题is this behavior undefined?
question about const reference有关objec access path的问题
C++ Q05: pointer to constant variableC++ 的 问题
谁给解释一下这个c question[合集] 请问-fno-implicit-templates的用处
问一个 char * 和 char [] 的问题不用头文件,如何调用函数?C++
相关话题的讨论汇总
话题: const话题: double话题: addr话题: pointer话题: pc