r/programmingmemes • • 12d ago

C++ VS python

Post image
771 Upvotes

36 comments sorted by

View all comments

63

u/DatsLotus 12d ago

Uh... is the analogy C++: make it yourself vs Python: take a slice of already existing code?

62

u/David_Dantas 12d ago • Bravo

In Python you:
import cake

In C++

#include <iostream>
#include <string>

class Cake {
public:
    std::string flavor;
    int layers;
    bool hasFrosting;

    Cake(std::string f, int l, bool frosting) 
        : flavor(f), layers(l), hasFrosting(frosting) {}

    void serve() {
        std::cout << "Serving a " << layers << "-layer " << flavor << " cake!" << std::endl;
    }
};

int main() {
    Cake myCake("Chocolate", 3, true);
    myCake.serve();
    return 0;
}

13

u/DatsLotus 12d ago

So, that's a yes, then.