Hey guys, I require some assistance with vectors & classes. A bit stuck so could use some guidance.
I have a class called Collectable.
At the moment within that class it is using an array of Coords (each coord has an X & Y). The array is fixed to 1 with a const int, this is so that only one 'Collectable' is ever spawned. The 'Collectable' class knows how to render itself with a gotoxy function which takes in a coord as a parameter & I loop through the array and draw whatever is in it at the coords it is at.
It also has a random position function which sets it position within a certain x & y area.
I wanted to build upon the 'Collectable' class & create another class that would use vectors which I could dynamically create multiple 'Collectable' objects with.
I created a 'collecthandler' class which contains the vector of Collectables in it.
I've done some research and I think I have set up a Vector of Collectables. However I am unsure how to proceed further. Since the original 'Collectable' class has everything to do with a 'Collectable'. I want to be able to use the methods within it.
I believe when I create the 'new collectable' within the vector it calls the 'Collectable' default constructor. I'm not sure whether I need to build upon its default constructor because at the moment all it does is setup a char value & bool for me. The rest is done within methods.
Ill paste some code below if my description was not able to help you understand my problem!
Thanks & sorry for the lengthy post.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
class Collectable
{
private:
Coord m_Collectable [m_maxCollectable]; //m_maxCollectable set to 1.
void renderCollectable(const Coord &coord); //how I render the collectable.
}
class CollectableHandler
{
private:
vector <Collectable*> m_collectables;
CollectableHandler::CollectableHandler()
{
m_collectables.push_back(new Collectable());
}
}
|