![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Does C++ compiler create default constructor when we write our own?
In this tutorial, we will be discussing a program to understand if the C++ compiler creates a default constructor when we write our own.
Generally, the C++ compiler uses the default constructor when no one is defined, but always uses the one defined by the user if any.
Example
#include<iostream> using namespace std; class myInteger{ private: int value; //other functions in class }; int main(){ myInteger I1; getchar(); return 0; }
Output
Compiles successfully
Example
#include<iostream> using namespace std; class myInteger{ private: int value; public: myInteger(int v) //user-defined constructor { value = v; } //other functions in class }; int main(){ myInteger I1; getchar(); return 0; }
Output
Gives error about user-defined constructor not being defined
Advertisements