There is no such thing as a dynamic constructor, but there is dynamic construction.
struct A {};
foo ()
{
A* x = new A; // dynamic construction.
// use x...
delete x;
}
The above instantiates x on the free store (the heap). Note that every call to new must be matched with a call to delete to release the memory resource. If we hadn't deleted x, then x would have fallen from scope when the function returned, but the instance of A would remain in memory and we'd have no way of recovering that memory until the program terminated.
In general it is best not to use dynamic allocation like this as it's all too easy to forget to delete the resource when we're done with it. A better method is to a statically allocated smart pointer instead:
foo ()
{
unique_ptr<A> x; // static allocation
// use x....
}
Smart pointers are overloaded so they behave just as if they were raw pointers so you can use them just as you normally would a raw pointer, but you must not delete them. When the smart pointer falls from scope it will invoke A's destructor automatically, thus we no longer need to remember to delete the pointer. This technique is central to Resource Acquisition Is Initialisation (RAII).
Yes.
True - A C++ constructor cannot return a value.
An implicit constructor call will always call the default constructor, whereas explicit constructor calls allow to chose the best constructor and passing of arguments into the constructor.
No. Constructors initialise objects and, by definition, must be able to modify the member variables. Uninitialised members are a disaster waiting to happen even without a constructor declared const! Thankfully, the compiler won't permit a const constructor.
dynamic constructor is a way to constructing an object based on the run type of some existing object. it basically uses standard virtual functions/polymorphism
A constructor is a method that fires when the object is instantiated. A friend function is a function that has special access to the object. They are two different types of things, and cannot be further differenced.
It cannot. Inheritance is a compile-time operation. Constructors are invoked at runtime at the point of instantiation.
There is no such thing as a constructor function in C++ (constructors have no return value, not even void, and cannot be called like regular functions). Constructors are invoked rather than called directly, either by declaring a static variable of the class type, or via the C++ new operator.
Static binding occurs at compile time. Dynamic binding occurs at runtime.
Initialization of objects means to provide an initial value for the object. This is usually done by the constructor, or it can be done with an assignment statement.
Not possible in C.
In C++, overriding and function, method, or operator is a different thing than (dynamic) polymorphism, so overriding a polymorphic method is almost entirely possible.