I have a object (House) which takes a number of other objects (Cat) in it's constructor. The number of objects it takes is unknown but there is a maximum number. The order the Cats are placed in the constructor is important as they will be acted on in that order. Currently, I'm default filling them. I had thought of using a vector in the House parameter list but there are several hundred possibilities and I'm not sure I'd want to generate a vector for each of them. Creating a function which generates a vector based on Cat objects seems to run into the same problem as the House Constructor.
Ultimately, what happens is a vector of Houses is constructed. However, only one of them is selected for use later. Once selected the Cat objects it holds are acted upon. Is there a better way?
Thanks.
class House
{
public:
House(const Cat& a = Cat(), const Cat& b = Cat(), const Cat& c = Cat(),
const Cat& d = Cat(), const Cat& e = Cat(), const Cat& f = Cat())
{
if (a.isValid() == true) m_vCats.push_back(a);
if (b.isValid() == true) m_vCats.push_back(;
if (c.isValid() == true) m_vCats.push_back(c);
if (d.isValid() == true) m_vCats.push_back(d);
if (e.isValid() == true) m_vCats.push_back(e);
if (f.isValid() == true) m_vCats.push_back(f);
}
private:
std::vector m_vCats;
};
int main()
{
Cat felix( Cat("felix") );
Cat morris( Cat("morris") );
Cat slyvester( Cat("sylvester") );
Cat fluffy( Cat("fluffy") );
Cat garfield( Cat("garfield") );
Cat heathcliff( Cat("heathcliff") );
Cat eric( Cat("eric the cat") );
std::vector vHouses;
vHouses.push_back( House(felix) );
vHouses.push_back( House(felix, garfield) );
vHouses.push_back( House(felix, heathcliff) );
vHouses.push_back( House(morris, slyvester) );
vHouses.push_back( House(eric, morris, garfield, slyvester) );
vHouses.push_back( House(felix, morris, eric, fluffy, garfield) );
vHouses.push_back( House(morris, felix, eric, fluffy, garfield) );
// Blah blah blah
// Do some stuff with one of the elements of vHouses.
}