In C++, compiler by default creates default constructor for every class. But, if we define our own constructor, compiler doesn’t create the default constructor.
For example, program 1 compiles without any error, but compilation of program 2 fails with error “no matching function for call to `myInteger::myInteger()’ ”
Please write comments if you find anything incorrect in the above GFact or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- When should we write our own copy constructor?
- When should we write our own assignment operator in C++?
- When does compiler create default and copy constructors in C++?
- How to implement our own Vector Class in C++?
- C++ default constructor | Built-in types
- Is body of a Default Constructor blank in C++?
- Write your own memcpy() and memmove()
- Write your own strlen() for a long string padded with '\0's
- How to write your own header file in C?
- Write a C program that does not terminate when Ctrl+C is pressed
- How to create a List with Constructor in C++ STL
- Input-output system calls in C | Create, Open, Close, Read, Write
- Implement Your Own sizeof
- Implement your own itoa()
- Implement your own tail (Read last n lines of a huge file)
- Implementing own Hash Table with Open Addressing Linear Probing in C++
- Making your own Linux Shell in C
- What are the default values of static variables in C?
- C++ Internals | Default Constructors | Set 1
- Templates and Default Arguments