I have a BossClass , and I will have 5 entries of BossClass in future. I need them to be organized as an array (to be passed to other class), what would be the preferred method?
Here is some code for clarifying my question.
class BossClass
{
public:
BossClass(int);
};
class MyClass
{
public:
MyClass(BossClass*[5]);
};
MyClass someFunction()
{
BossClass* bossClasses[5]; //[1]
for (int i=0; i<5; i++)
{
// After some interactive input......
bossClasses[i] = new BossClass(i);
}
return new MyClass(bossClasses); //[2]
}
the problem in this code is, I cannot instantiate MyClass at [1] because the default constructor is not defined. I cannot change the BossClass (but i can change MyClass) as a workaround handling the array of data. What should I do here?
edit: corrected for some really logical errors. The compiler now calls for error with the message
error: incompatible types in assignment of ‘BossClass**’ to ‘BossClass* [0]’ at [2]
And I am curious why array is not assignable to a pointer, as a further question.