When you declare an instance of a class, why are you only allowed to use the default constructor of that class? For example:
class A{
public:
A ( ); //default
A ( int j );
int myInt;
}
legal:
A myArray[5];
illegal:
A myArray[5](10);
When you declare an instance of a class, why are you only allowed to use the default constructor of that class? For example:
class A{
public:
A ( ); //default
A ( int j );
int myInt;
}
legal:
A myArray[5];
illegal:
A myArray[5](10);
you don't have to use the default constructor. You can make an assortment of constructors to do whatever you want depending on what is passed.
...
A(int this)
{
my_private_member_data = this;
}
....
then
A instantiation[5](2);
is valid.
Last edited by Betazep; 12-06-2001 at 11:37 PM.
Blue
no, it's not valid...A instantiation[5](2);
is valid.
The problem with...
>>> A instantiation[5](2);
... is ambiguity, which member of the array will have the value 2? The correct way to do this is...
A instatiation[5] = {2,2,2,2,2};
... one value for each constructor, no ambiguity.
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.