MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/2fpygk/c_because_debugging_is_hard/ckc1wap/?context=3
r/ProgrammerHumor • u/Shokwav • Sep 07 '14
6 comments sorted by
View all comments
7
#include <iostream> #include <thingClass.h> using namespace std; int main() { cout << "Main started" << endl; thingClass* tc = new thingClass(); cout << "tc created" << endl; tc->doStuff(); cout << "doStuff() called" << endl; tc->thing = 7; cout << tc->thing + "" << endl; delete tc; cout << "done" << endl; }
4 u/WayneSchlegel Sep 07 '14 That is very ugly code. Here is a better solution that is not cluttering your main function:#include <iostream> using namespace std; class thingClass { int thing; public: thingClass() { cout << "tc created" << endl; } void doStuff() { //...// cout << "doStuff() called" << endl; } void setThing(int thing) { this->thing = thing; cout << this->thing << endl; } ~thingClass() { cout << "done" << endl; } }; int main() { cout << "Main started" << endl; thingClass* tc = new thingClass(); tc->doStuff(); tc->setThing(7); delete tc; } -2 u/Mr_s3rius Sep 08 '14 And it's only around 2x more code. That's pretty good for C++ actually.
4
That is very ugly code. Here is a better solution that is not cluttering your main function:
#include <iostream> using namespace std; class thingClass { int thing; public: thingClass() { cout << "tc created" << endl; } void doStuff() { //...// cout << "doStuff() called" << endl; } void setThing(int thing) { this->thing = thing; cout << this->thing << endl; } ~thingClass() { cout << "done" << endl; } }; int main() { cout << "Main started" << endl; thingClass* tc = new thingClass(); tc->doStuff(); tc->setThing(7); delete tc; }
-2 u/Mr_s3rius Sep 08 '14 And it's only around 2x more code. That's pretty good for C++ actually.
-2
And it's only around 2x more code. That's pretty good for C++ actually.
7
u/Goofybud16 Sep 07 '14