>Can anyone explain me in simple language and better if with an
>example why constructor don't have return types
Here's an idea. Show us how it could be done without breaking all kinds of existing code, and you'll answer your own question.
Another option -- don't put any code in the constructor that might cause it to fail. M$ MFC is good at that -- first instantiate the object and then call its Create() method. The constructor only initializes class data to some default value (normally 0). Then the Create() method initializes all the rest and either returns a value or throws and exception.
Yes, one could use MFC's 2-stage construction. However, my personal preference is still to to use the constructor to create the object, because I'm used to the RAII paradigm, and my own wrappers for the Windows API use it.
since every function should return a type so do consttructors(they return the type of the class ).but being the special member function according to the previliges provided by the developer we can't access that type
( i think so.) Becoz
i know that it may create a temporery object and then copy that in memory space in cls_varand then destroy the temporery.
But another aspect may be that it has a internally usable type(constructor type).
Can anyone explain me in simple language and better if with an example why constructor don't have return types :!:
constructors are meant to initialize your data members in your classes. They dont return any type because that was how they were built and programmed to work. Constructors dont even take a void type...thats the beauty of it....the set values to your data members and ensure proper initialization so that your program doesnt have garabge values and such
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 ...