QUESTION 12)
12A) Any idea why I can't access the set'ers of this 3rd party Sprite class via the iterator, but I can access the get'ers via the same iterator just fine? I can access the set'ers via array [] subscript though. I tried making my own class & trying the same & it works just fine with my own.
12B) What container do you think I should use?
1) vector- constant time insertion/deletion at end.
2) deque- constant time insertion/del at end & beginning
3) list- constant time insertion/del anywhere, linked list
4) forward_list- const time insertion at front of list & going forward, not sure about the deletion though but it is probably constant front del too.
5) set- quick & frequent find/search via key (key is the data)
6) map- - quick & frequent find/search via key relative to data
Now, I think I may likely do frequent searches based on x position eventually, BUT the x position will change constantly & this cannot be used as key to lookup via set & map...because you cannot change them if they are used as keys in set & map. Also, I am not worried about insertion time as all that will be done at start of program, but more quick access & manipulation time of the data in the class, so I guess vector or list is just fine. I could probably easily just do it with a * new Sprite []/delete[] too.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
vector<Sprite>::const_iterator iter = scalesSprites.cbegin();
int xGrowFactor = 0;
for (iter; iter != scalesSprites.cend(); ++iter, xGrowFactor += 150)
{
//(*iter).setTexture(texture); //NOT WORK
//iter->setTexture(texture); //NOT WORK
iter->getTexture(); //WORKS
}
//WORKS for access with array [] subscript
for (auto i = 0; i < scalesSprites.size(); ++i, xGrowFactor += 150)
{
scalesSprites[i].setTexture(texture);
scalesSprites[i].setScale(.5, .5);
scalesSprites[i].setPosition(xGrowFactor, 800);
}
|
12C) What main C++ are the rest of you reading/have read? How much time have you spent on it & how long did it take you to learn it? How long do you think you will have to spend on the C++23 future book?