As you say C++ needs constructors that are not ordinary functions for things like in-place construction.
However this is a very bad and unnecessary hack, which I consider as the worst mistake of C++ (already present in the first "C with Classes", before becoming C++).
The correct solution is to distinguish output parameters from input-output parameters, like e.g. in Ada.
The difference is that an input-output parameter contains memory on which some object has already been constructed before invoking the function, while an output parameter contains uninitialized memory upon function entry.
In a language that has 3 parameter types (input, output and input-output), constructors are just ordinary functions that have an output parameter of the type that is constructed. No special treatment for constructors is needed.
When defining classes, one would have to optionally specify only a default constructor and a destructor, because these must be invoked implicitly by the compiler. Any explicit initialization of an object would use arbitrary functions with suitable parameter types.
The result parameter of a function should be an output parameter. If an already existing object is passed as an output parameter to a function, inclusively for its result parameter, the compiler would invoke implicitly the destructor for that class, before invoking the function.
Both output parameters and input-output parameters may be passed either by value or by reference, based on compiler or on ABI choices that are appropriate for their types.
When output parameters are passed by value, in registers, the compiler will store an output parameter from its register to the desired location, after the function returns, while when input-output parameters are passed by value, in registers, the compiler will load those registers before invoking the function and store them after the function returns.
However this is a very bad and unnecessary hack, which I consider as the worst mistake of C++ (already present in the first "C with Classes", before becoming C++).
The correct solution is to distinguish output parameters from input-output parameters, like e.g. in Ada.
The difference is that an input-output parameter contains memory on which some object has already been constructed before invoking the function, while an output parameter contains uninitialized memory upon function entry.
In a language that has 3 parameter types (input, output and input-output), constructors are just ordinary functions that have an output parameter of the type that is constructed. No special treatment for constructors is needed.
When defining classes, one would have to optionally specify only a default constructor and a destructor, because these must be invoked implicitly by the compiler. Any explicit initialization of an object would use arbitrary functions with suitable parameter types.
The result parameter of a function should be an output parameter. If an already existing object is passed as an output parameter to a function, inclusively for its result parameter, the compiler would invoke implicitly the destructor for that class, before invoking the function.
Both output parameters and input-output parameters may be passed either by value or by reference, based on compiler or on ABI choices that are appropriate for their types.
When output parameters are passed by value, in registers, the compiler will store an output parameter from its register to the desired location, after the function returns, while when input-output parameters are passed by value, in registers, the compiler will load those registers before invoking the function and store them after the function returns.