From c7d0e46064a4f7fdeee2ef53a3d51b20c9784d8a Mon Sep 17 00:00:00 2001 From: nagrat Date: Tue, 14 Mar 2023 19:52:10 +0000 Subject: [PATCH] Added constructors.cpp --- Classes and Inheritance/constructors.cpp | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Classes and Inheritance/constructors.cpp diff --git a/Classes and Inheritance/constructors.cpp b/Classes and Inheritance/constructors.cpp new file mode 100644 index 0000000..f189f5f --- /dev/null +++ b/Classes and Inheritance/constructors.cpp @@ -0,0 +1,26 @@ +#include + +using namespace std; + +/* + Constructors, building blocks part of OOP. + Quite weird imo, but they are cool at the same time. +*/ + +class ContructMe { // defining class + public: // public access + ContructMe() { // constructor with the same name as class name + cout << "You just called me!" << endl; // what will be called when you make the object of the class + } + + void func() { + cout << "Hello, from func()" << endl; // sample function i added for clarity below + } +}; + +int main() { + ContructMe cm; // making the object of the class and it calls the constructor + cm.func(); // calls the func that was made above - to show that the class is behaving normally + // and not anything different as with the constructor varient. + return 0; // return 0 +} \ No newline at end of file