I'm new to C++, and have experience with other programmas languages, but I have a question: How can I access a list from a sub class, from the parent?
Here is my layout: TutorialApp.cpp with function TutorialApp::update() In that function I want to access the list mParticles2y from another class that list is made in: ParticleController.cpp, like this:
std::list<int> mParticles2y;
I've tried accessing the list like this [in TutorialApp]:
mParticleController.mParticles2y.size()
[to get it's size]
but that gives me this error:
call of an object of a class type without appropriate operator
So I dont really know where to go from here...
PS: I use mParticleController because that is state in my script:
ParticleController mParticleController;
I hope this is enough info.
PS: I'm not really sure this is called a class, or child, I use these terms because I know them from ActionScript [which works with classes in a similar way]
Your code for the loop that has the errors should look more like this. It may not compile exactly since I can't compile it easily at the moment. This isn't the ideal way to go about it, but it is the minimal impact to your code. I would move this loop to the ParticleController class as a member function that returned true/false to indicate a hit. It would be better encapsulated that way.
for(std::list<int>::iterator yit = mParticleController.mParticles2y.begin(),
std::list<int>::iterator xit = mParticleController.mParticles2x.begin();
yit != mParticleController.mParticles2y.end() && xit != mParticleController.mParticles2x.end();
yit++, xit++)
{
if(
(coordy >= *it) && (coordy <= (*it) + 40) &&
(coordx >= *xit) && (coordx <= (*xit) + 40)
)
{
mParticleController.removeTargetedParticles(i); //remove blokje
score += 1; //score verhogen
}
}