// // CC -I/usr/local/include/stl -mips3 -n32 -o class class.cc // Needs stl from http://www.sgi.com/tech/stl/stl.tar.gz // #include #include using namespace std; class Hello { public: Hello(); Hello(string s); ~Hello(); string get_hello() { return hello_world; } void set_hello(string s) { hello_world=s; } private: string hello_world; }; class Talk: public Hello { friend class Colega; // Otherwise: // "class.cc", line 35: error(1238): member "Talk::w" is inaccessible // void insult_also(Talk *t, string word) { t->w = word; } // ^ public: Talk(string who) {w=who;} void insult(string word) {w=word;} string get_w() { return w; } private: string w; }; class Colega { public: void insult_also(Talk *t, string word) { t->w = word; } }; Hello::Hello() { cout << "inside Hello constructor" << endl; } Hello::Hello(string s) { cout << "inside Hello string constructor" << endl; hello_world=s; } Hello::~Hello() { cout << "inside Hello destructor" << endl; hello_world=""; } int main(int argc, char *argv[]) { Hello h; Hello hello("Hola"); Talk t("Fulano"); Colega c; h.set_hello("Hello, World!"); cout << h.get_hello() << endl; cout << hello.get_hello() << endl; t.set_hello("Hello, Fulano"); cout << t.get_w() << endl; cout << t.get_hello() << endl; t.insult("Fulano, eres un cerdo"); cout << t.get_w() << endl; c.insult_also(&t, "Fulano es realmente un cerdo"); cout << t.get_w() << endl; return 0; }