The problem here isn't so much to do with the dynamic allocation as it is the pluralisation of object.
Dynamically invoking a non-default constructor is a simple as a static instance:
1 2
|
CButton *ptr;
ptr = new CButton(1,2,3,4);
|
The problem here is that you have a pointer to an array. You can't specify what to do with each item at the point of instantiation, so the compiler is looking for the default constructor, which doesn't exist.
I think the best solution is to write a new default constructor. Then write a Set method to set the values.
1 2 3 4 5 6 7
|
class CButton
{
private:
// Member vars here
public:
CButton():x(0),y(0),width(0),height(0){}
};
|
That constructor will run when the dynamic instances are created, since you don't specify parameters. Remember that as soon as you write your own constructor, the default one is no longer available.
You can then set each one using a Set method, which will do more or less the same thing as your current constructor:
Of course, in my default constructor I set everything to zero as an example. You may be able to default the values to something more meaningful.
Hope this helps.