Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class Dupa {
- public:
- int *i;
- std::string string;
- Dupa(std::string string) {
- std::cout << "konstruktor " << string << std::endl;
- this->string = string;
- i = new int(5);
- }
- Dupa(Dupa &other) {
- std::cout << "kopiujący" << std::endl;
- i = new int(*other.i);
- this->string = other.string + "_copy";
- }
- void operator=(Dupa other) {
- std::cout << "oeprator =" << std::endl;
- i = new int(*other.i);
- string = other.string + "_=";
- }
- Dupa operator+(Dupa other) {
- std::cout << "++++" << std::endl;
- Dupa dupa("dupa_op_+");
- *dupa.i = *i + *other.i;
- dupa.string = string + other.string;
- return dupa;
- }
- ~Dupa() {
- std::cout << "delete" << std::endl;
- delete i;
- }
- void print() {
- std::cout << "print: " << *i << std::endl;
- }
- };
- int main() {
- Dupa p1("pierwej");
- Dupa p2("drugiej");
- Dupa p3("trzeciej");
- p3 = p1 + p2;
- std::cout << "hehe" << std::endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment