Yes we can do so . We can create an array of objects for any class , irrespective of whether it has a default constructor or not . Moreover , the default constructor is also provided by the compiler . :D
If some constructors are defined, but they are all non-default,
the compiler will not implicitly define a default constructor.
Hence, a default constructor may not exist for a class.
This is the reason for a typical error which can be demonstrated
by the following example.
MyClass (int y); // a value constructor
MyClass :: MyClass (int y)
x = y;
MyClass object(100); // value constructor called
MyClass* pointer; // do not need to know about any existing ctors
pointer = new MyClass; // error: no default constructor
No we cannot do so because when if we define a single constructor in the class than the compiler does not provide default constructor , so in that situation we have compulsary write the default constructor otherwise it creates error
Your reply is true ... in the case where your design actually does call (i.e. the program uses it) the default ctor ... other-wise (sometimes) ... you may not want to code for the default ctor ... i.e. the case where you want your compiler to issue an error if programmer inadvently codes for a call to the default ctor (and your design was to prevent that from happening.)
so in the above program which u have posted in that u have define a constructor which takes single argument so the compiler does not provide an default constructor and throws an error tha "no default constructor"
Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...