If a class has only one constructor with one parameter, how to declare an array? I know that vector is recommended in this case. For example, if I have a class
If it makes sense for your class, you could provide a default value for your constructor parameter:
class Foo
{
public:
explicit Foo(int i = 0);
}
Now you have a default constructor. (A "default constructor" is a constructor that can be called with no arguments: FAQ)
I'd also recommend making your constructor explicit, as I did above. It will prevent you from getting Foo
s from int
s when you don't want request them.