P
Pelle Beckman
Hi all,
I have a few - beginners - questions:
* Why can't I put object references in a std::vector,
i.e std::vector<MyClass&> ?
At least in doesnt work in gcc (mingw, win32)
* What's the difference between passing
member inits in the c-tor funtion from
doing them as "ordinary" vars?
i.e
MyClass::MyClass : my_member1 (5), my_member (2) { }
as opposed to
MyClass::MyClass { my_member1 = 5; my_member = 2; }
* I'm looping through a std::vector using iterators.
Under some criterias I want to access certain elements
of that vector using the following code:
std::vector<MyClass>::iterator it = MyVector.begin();
int i = 0;
while (it != MyVector.end()) {
if (some_condition) {
MyVector.at(i) = some_value;
}
i++;
it++;
}
Isn't there some way to do this without
using the somewhat ugly "i" value? Is there some
way of using the iterator as a vector element "indexer"?
Thanks,
-- Pelle
I have a few - beginners - questions:
* Why can't I put object references in a std::vector,
i.e std::vector<MyClass&> ?
At least in doesnt work in gcc (mingw, win32)
* What's the difference between passing
member inits in the c-tor funtion from
doing them as "ordinary" vars?
i.e
MyClass::MyClass : my_member1 (5), my_member (2) { }
as opposed to
MyClass::MyClass { my_member1 = 5; my_member = 2; }
* I'm looping through a std::vector using iterators.
Under some criterias I want to access certain elements
of that vector using the following code:
std::vector<MyClass>::iterator it = MyVector.begin();
int i = 0;
while (it != MyVector.end()) {
if (some_condition) {
MyVector.at(i) = some_value;
}
i++;
it++;
}
Isn't there some way to do this without
using the somewhat ugly "i" value? Is there some
way of using the iterator as a vector element "indexer"?
Thanks,
-- Pelle