Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added constructors.cpp
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <iostream> | ||
|
||
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 | ||
} |