由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Computation版 - C++ questions
相关主题
问个C++读入文件的问题问一个c++问题关于reference vs. pointer
请问怎样让一m长的向量和一mxn的矩阵相乘,仍为mxn抠字眼:assignment and initialize in C++
Bioinformatics Software Developer (Bethesda, MD)C++ Q05: pointer to constant variable
choose three items of various weights to will fit into a knapsack of capacity 5static initialization dependency c++
Invited Review Articles at JPRone question about initializaiton list
渣打 天津 招 unix system supportstatic initialization dependency c++ (转载)
c++ initialize struct一道 memset in C++的题
面试就是面试问题,跟实际问题差太远c++ 不自动initialize变量么?
相关话题的讨论汇总
话题: c++话题: questions话题: allowed话题: variable话题: switch
进入Computation版参与讨论
1 (共1页)
Q***5
发帖数: 994
1
I'm working through D. Rajan's Challenges with C++, and have some questions
n******t
发帖数: 4406
2
The definition appears at line X, makes the i available to the whole switch
control statement and you initialized it, C++ does not allow this to happen,
because other wise you could use some variable without actually
initializing it.
This type of questions is really pedantic, a well-trained programmer won't
really come to situations like this.

questions

【在 Q***5 的大作中提到】
: I'm working through D. Rajan's Challenges with C++, and have some questions
Q***5
发帖数: 994
3
Thanks. But I still don't quite understand your point about initialization.
For example, if we change line X to
int i; i = 10;
to change initialization to assignment, is that allowed?
or no declaration of variable inside a switch at all?

switch
happen,

【在 n******t 的大作中提到】
: The definition appears at line X, makes the i available to the whole switch
: control statement and you initialized it, C++ does not allow this to happen,
: because other wise you could use some variable without actually
: initializing it.
: This type of questions is really pedantic, a well-trained programmer won't
: really come to situations like this.
:
: questions

n******t
发帖数: 4406
4

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is allowed. Because now you define a variable WITHOUT initializing it.
So C++ believes that you will do the assignment yourself. Just like those
simple
case with out switch control.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It is allowed, but a declaration of variable with initializer while could
be potentially jumped over, is not allowed.

【在 Q***5 的大作中提到】
: Thanks. But I still don't quite understand your point about initialization.
: For example, if we change line X to
: int i; i = 10;
: to change initialization to assignment, is that allowed?
: or no declaration of variable inside a switch at all?
:
: switch
: happen,

Q***5
发帖数: 994
5
Got you. Thanks.

【在 n******t 的大作中提到】
:
: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: This is allowed. Because now you define a variable WITHOUT initializing it.
: So C++ believes that you will do the assignment yourself. Just like those
: simple
: case with out switch control.
: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: It is allowed, but a declaration of variable with initializer while could
: be potentially jumped over, is not allowed.

1 (共1页)
进入Computation版参与讨论
相关主题
c++ 不自动initialize变量么?Invited Review Articles at JPR
公司面试的人问:do you have any question?渣打 天津 招 unix system support
C++: 如何对const data member做assignment?c++ initialize struct
anyone saw this on code?面试就是面试问题,跟实际问题差太远
问个C++读入文件的问题问一个c++问题关于reference vs. pointer
请问怎样让一m长的向量和一mxn的矩阵相乘,仍为mxn抠字眼:assignment and initialize in C++
Bioinformatics Software Developer (Bethesda, MD)C++ Q05: pointer to constant variable
choose three items of various weights to will fit into a knapsack of capacity 5static initialization dependency c++
相关话题的讨论汇总
话题: c++话题: questions话题: allowed话题: variable话题: switch