#include #include #include // Lösningen ska visa förståelse för hur operatorer skrivs och // huruvida operatorn kan/bör skrivas som medlem eller som fri // funktion. class Four_Letter_Word { public: Four_Letter_Word(std::string const& w) : word{w} { check(w); } std::string get() const { return word; } void set(std::string const& w) { check(w); word = w; } std::string operator*(int n) const { std::string ret{}; for ( int i{}; i < n; ++i ) { ret += word; } return ret; } private: void check(std::string const& w) const { if ( w.length() != 4 ) { throw std::logic_error{"Not a four letter word"}; } } std::string word; }; using namespace std; int main() { Four_Letter_Word const w{"Frak"}; cout << w*5 << endl; Four_Letter_Word f{"f*n"}; }