Last active
April 12, 2021 07:22
-
-
Save debdutdeb/9a7d6684e5ea503630276284e9a3ce75 to your computer and use it in GitHub Desktop.
I like how C++ programs look
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
#include <iostream> | |
class Printable { | |
public: | |
virtual void print() = 0; | |
}; | |
class I : public Printable { | |
private: | |
std::string *name; | |
public: | |
I(std::string name); | |
~I(); | |
void print(); | |
}; | |
I::I(std::string name){ | |
this->name = new std::string {name}; | |
} | |
I::~I() { delete this->name; } | |
void I::print(){ | |
std::cout << "The name is: " << *this->name << std::endl; | |
} | |
int main | |
(int argc, char ** argv, char **envp) | |
{ | |
I me{"Debdut Chakraborty"}; | |
me.print(); | |
return 0; | |
} |
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
#include <iostream> | |
#include <ostream> | |
class I { | |
private: | |
std::string *name; | |
public: | |
I(std::string name); | |
~I(); | |
inline friend std::ostream& operator<<(std::ostream& out, const I& me) | |
{ | |
out << "The string output is: " << *me.name; | |
return out; | |
} | |
}; | |
I::I(std::string name){ | |
this->name = new std::string {name}; | |
} | |
I::~I() { delete this->name; } | |
int main | |
(int argc, char ** argv, char **envp) | |
{ | |
I me{"Debdut Chakraborty"}; | |
std::cout << me << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment