Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- class vec {
- private:
- double x;
- double y;
- public:
- vec(double n, double m){
- x = n;
- y = m;
- cout <<"конструктор с параметрами\n";
- }
- vec(){
- cout<<"здесь вызывается конструктор по умоч\n";
- }
- ~vec(){
- cout << "вызывается деструктор\n";
- }
- vec(const vec &a){
- cout<<"копирования\n";
- }
- friend vec& operator*= (vec& v1, vec& v2);
- friend vec& operator+= (vec& v1, vec& v2);
- friend vec& operator+ (const vec& v1, const vec& v2);
- void show(){
- cout << x << " " << y;
- cout << endl;
- }
- };
- vec& operator*=(vec& v1, vec& v2){
- v1.x *= v2.x;
- v1.y *= v2.y;
- return v1;
- }
- vec& operator+=(vec& v1, vec& v2){
- v1.x += v2.x;
- v1.y += v2.y;
- return v1;
- }
- vec v3;
- vec& operator+(const vec& v1, const vec& v2){
- v3.x = v1.x + v2.x;
- v3.y = v1.y + v2.y;
- return v3;
- }
- void rr(vec v){
- v.show();
- }
- int main(){
- vec v1;
- vec v2(2.0,2.0);
- vec v3(7.0,6.0);
- v1 = v2 + v3;
- v1.show();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement