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...... : : <>
|
|