由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Is it possible to initialize container in initialization list?
相关主题
再问C++初始化问题。static vector 怎么 initialize ?
两个继承问题static initialization dependency c++
question about c++ constructorquestion on reserve() in vector container.
请教pthread producer-consumer问题one question about initializaiton list
前几天有人问rvalue reference的how to initialize associate data in STL map
C++要是有null object就好了一道 memset in C++的题
【C++】请问这样有没有memory leak?多谢c++ 不自动initialize变量么?
Question about vector as a class member能帮我看看Ruby的这道题吗?
相关话题的讨论汇总
话题: initialize话题: vector话题: int话题: possible
进入Programming版参与讨论
1 (共1页)
d*******n
发帖数: 524
1
Let's say I have a class A defined as follows. The vector v as a member of
the class should be initialized to have size = 10. The following code does
this job. However, I am wondering if it is possible to initialize v in the
initialization list, i.e., the same way that a is initialized?
class A{
int a;
vector v;
public:
A() : a(0) {
v = vector(10);
}
}
z****e
发帖数: 2024
2
class A{
int a;
vector v;
public:
A() : a(0),v(vector(10)) {
cout< }
};
or:
A::A() : a(0),v(10) {
cout< }
t****t
发帖数: 6806
3
no it is not possible for now. for c++0x you can use std::initializer_list<>
(the {1, 2, 3} syntax) to initialize it.

【在 d*******n 的大作中提到】
: Let's say I have a class A defined as follows. The vector v as a member of
: the class should be initialized to have size = 10. The following code does
: this job. However, I am wondering if it is possible to initialize v in the
: initialization list, i.e., the same way that a is initialized?
: class A{
: int a;
: vector v;
: public:
: A() : a(0) {
: v = vector(10);

d*******n
发帖数: 524
4
but zaoxie's suggestion worked......

<>

【在 t****t 的大作中提到】
: no it is not possible for now. for c++0x you can use std::initializer_list<>
: (the {1, 2, 3} syntax) to initialize it.

t****t
发帖数: 6806
5
oh i thought you need to fill in the content. size only is ok.

【在 d*******n 的大作中提到】
: but zaoxie's suggestion worked......
:
: <>

1 (共1页)
进入Programming版参与讨论
相关主题
能帮我看看Ruby的这道题吗?前几天有人问rvalue reference的
C++ 中 myobject * a =new myobject[n] 的问题C++要是有null object就好了
[合集] a simple c++ puzzle【C++】请问这样有没有memory leak?多谢
谁给新手解释一下这个c++小程序Question about vector as a class member
再问C++初始化问题。static vector 怎么 initialize ?
两个继承问题static initialization dependency c++
question about c++ constructorquestion on reserve() in vector container.
请教pthread producer-consumer问题one question about initializaiton list
相关话题的讨论汇总
话题: initialize话题: vector话题: int话题: possible