Is there a default default constructor? [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
If you don't provide a copy constructor, one is created automatically. This is called the default copy constructor.
A default constructor is a constructor that doesn't take any parameters.
If you don't provide any constructors, a default constructor is created automatically.
Is this called the default default constructor?

No, the default constructor is called a “default constructor” in both cases, whether it is provided explicitly or is automatically generated by the compiler.

Well, to be fair the C++ Standard does speak, in paragraph 12.1-5, of defaulted default constructors.

No. It's always called the default constructor.

It can be called an "implicitly defined default constructor", if you insist. C++11 §12.1/6
A default constructor that is defaulted and not defined as deleted is implicitly defined ...

Related

Is the term user-declared constructor ambiguous or is it self explanatory [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 months ago.
Improve this question
I came to know that the C++ standard doesn't define the term user-declared constructor but it uses that term at many places. Now to my current understanding, the term user-declared constructor is self explanatory.
But one user disagrees with my above understanding as they say:
It's not entirely self explanatory. The place things get tricky is with special member functions of things in the standard library. Even though a normal user never writes the code for constructors of things like std::string, I believe those still fall within the realm of "user declared" special member functions--but I can't quote anything from the standard to back that up, and there are fair arguments to be made that they're not.
So my question is that should the term user-declared constructors be defined by the standard? That is, is there any example where there is some ambiguity due to the term as said by the above quoted comment or is the term self-explanatory.
My current understanding is that user-declared in this context means "written by the user". That is, "which is not implicitly synthesized".
This is CWG2632 and the potential ambiguity(if any) will be resolved by adding the resolution given there:
user-declared [defns.user.declared]
declared in a translation unit using a declarator-id
[ Note 1 to entry: In contrast, some special member functions can be implicitly declared by the implementation. -- end note]

Use case of explicit deletion of move constructor in C++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I understand move constructor, but in some places I see move constructor is deleted. In what scenarios is deleting a move constructor is useful/makes sense?
Even if the the object needs to be singleton, we can delete the copy constructor but not the move constructor.
Its generally not needed, other than for purposes of being verbose. Just an example of "can doesnt mean should". In your example of deleting the copy constructor (or even just defined), the move constructor is implicitly deleted. In scenarios where this is done, you could imagine explicitly deleting the move constructor as well.

dynamic allocation of class object without constructor [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
How can I dynamically allocate a class object that has no defined constructor?
I tried:
A * newPtr = new A();
But it's giving me some kind of memory leak on gdb.
Cheers!
If there's no defined constructor and standard rules allow it then you get a implicitly-declared default constructor, otherwise your code wouldn't compile at all.
So if you are not defining any constructor and your code compiles then for sure a default one is declared and defined (so you actually have a constructor).
You get a leak because you need to delete the pointer to free its memory from the heap.

Concept of vptr and vtable in C++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Why only default constructor only able to create vptr(Virtual Table Pointer) and vtable(Virtual Table)? Why parameter constructor not able to
First, vtables and vptrs are not specified by the C++ language standard.
They're an implementation detail, although as far as I know all extant C++ implementation use that technique to implement virtual function dispatch.
With such an implementation, all constructors for a class with virtual member functions, necessarily establish the object's vptr. Things wouldn't work without it. So …
” Why parameter constructor not able to
… is simply an incorrect assumption.
Assuming the implementation uses vtables (a pretty common implementation choice, as noted by "Cheers and hth - Alf"), the creation/population of vtables and invoking constructors are distinct operations.
However, all instances of a given (non-abstract) class will - once constructed fully - have the same set of vtables (a class that inherits from multiple bases may have more than one vtable). There will certainly not be a different vtable depending on how the object is constructed (e.g. what parameters are passed to constructors, which constructor is invoked, etc).

Understanding Constructors in C++ [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I don't understand the purpose of constructors and how they function in C++. I understand that a constructor a is a function within a class that has the same name as the class but does not have a return type.
The purpose of a constructor in C++ is to reliably initialize raw memory, turning it into a useful object by establishing the chosen class invariant (what you can always assume about the object between calls of its member functions).
In contrast, an assignment has to change the value of an already initialized object, and may for example have to deallocate buffers that already have been established.
As long as you don't use very low level features of the language there is effectively a constructor call guarantee: that every object instantiated from a type T that has at least one user defined constructor, gets a single external call to a T constructor, which happens before anything else. Conversely, when you call a constructor by using the type name as a pseudo function name, T(), or with arguments, a T object is created. So the guarantee works both ways, and means that object creation involves constructor call and vice versa.